Subject: | Better Error Messages for libxslt |
I think it would be a good idea to apply the patch at <http://ahinea.wordpress.com/
2006/07/14/libxslt-error-reporting-fix/> in order to improve the error reporting capabilities.
I frequently get errors where I get no useful info at all...
I've attached the patch in case the web site is down.
-Dom
Subject: | xml-libxslterror-reporting-patch.txt |
*** XML-LibXSLT-1.58/LibXSLT.xs 2005-08-05 16:31:54.000000000 +0300
--- XML-LibXSLT-1.58-fixed-libxslt1.1.17-ivan-local/LibXSLT.xs 2006-07-08 11:00:52.000000000 +0300
***************
*** 20,23 ****
--- 20,24 ----
#include <libxml/tree.h>
#include <libxml/parser.h>
+ #include <libxml/globals.h>
#include <libxml/parserInternals.h>
#include <libxml/xpathInternals.h>
***************
*** 31,34 ****
--- 32,50 ----
#endif
+ /*** Error handling ***/
+
+ static xmlGenericErrorFunc xmlGenericError_original;
+ static void* xmlGenericErrorContext_original;
+
+ #define SET_ERROR_HANDLERS() \
+ xsltSetGenericErrorFunc(NULL, (xmlGenericErrorFunc)LibXSLT_error_handler); \
+ xmlGenericError_original = xmlGenericError; \
+ xmlGenericErrorContext_original = xmlGenericErrorContext; \
+ xmlSetGenericErrorFunc(NULL, (xmlGenericErrorFunc)LibXSLT_error_handler);
+
+ #define RESTORE_ERROR_HANDLERS() \
+ xmlSetGenericErrorFunc(xmlGenericErrorContext_original, (xmlGenericErrorFunc)xmlGenericError_original);
+
+
#define SET_CB(cb, fld) \
RETVAL = cb ? newSVsv(cb) : &PL_sv_undef;\
***************
*** 696,700 ****
--- 712,720 ----
xsltSetGenericDebugFunc(NULL, NULL);
}
+
+ SET_ERROR_HANDLERS();
RETVAL = xsltParseStylesheetDoc(doc_copy);
+ RESTORE_ERROR_HANDLERS();
+ if (SvTRUE(ERRSV)) { croak( SvPV_nolen(ERRSV) ); }
/*
***************
*** 727,731 ****
--- 747,754 ----
xsltSetGenericDebugFunc(NULL, NULL);
}
+ SET_ERROR_HANDLERS();
RETVAL = xsltParseStylesheetFile(filename);
+ RESTORE_ERROR_HANDLERS();
+ if (SvTRUE(ERRSV)) { croak( SvPV_nolen(ERRSV) ); }
/*
***************
*** 789,793 ****
--- 812,819 ----
(xmlInputReadCallback) LibXSLT_input_read,
(xmlInputCloseCallback) LibXSLT_input_close);
+
+ SET_ERROR_HANDLERS();
real_dom = xsltApplyStylesheet(self, doc, xslt_params);
+ RESTORE_ERROR_HANDLERS();
/*
***************
*** 798,804 ****
if (real_dom == NULL) {
if (SvTRUE(ERRSV)) {
! croak("Exception occurred while applying stylesheet: %s", SvPV(ERRSV, len));
}
- croak("Error applying stylesheet: %s", "(get error out of libxslt)");
}
if (real_dom->type == XML_HTML_DOCUMENT_NODE) {
--- 824,835 ----
if (real_dom == NULL) {
if (SvTRUE(ERRSV)) {
! croak("Error while applying stylesheet: %s", SvPV_nolen(ERRSV));
! } else {
! croak("Unknown error while applying stylesheet");
! }
! } else {
! if (SvTRUE(ERRSV)) {
! warn( "Non-fatal errors while applying stylesheet: %s", SvPV_nolen(ERRSV) );
}
}
if (real_dom->type == XML_HTML_DOCUMENT_NODE) {
***************
*** 845,854 ****
xsltSetGenericDebugFunc(NULL, NULL);
}
real_dom = xsltApplyStylesheet(self, xmlParseFile(filename), xslt_params);
if (real_dom == NULL) {
if (SvTRUE(ERRSV)) {
! croak("Error applying stylesheet: %s", SvPV(ERRSV, len));
}
- croak("Error applying stylesheet: %s", "(get error out of libxslt)");
}
if (real_dom->type == XML_HTML_DOCUMENT_NODE) {
--- 876,892 ----
xsltSetGenericDebugFunc(NULL, NULL);
}
+ SET_ERROR_HANDLERS();
real_dom = xsltApplyStylesheet(self, xmlParseFile(filename), xslt_params);
+ RESTORE_ERROR_HANDLERS();
if (real_dom == NULL) {
if (SvTRUE(ERRSV)) {
! croak("Error while applying stylesheet: %s", SvPV_nolen(ERRSV));
! } else {
! croak("Unknown error while applying stylesheet");
! }
! } else {
! if (SvTRUE(ERRSV)) {
! warn( "Non-fatal errors while applying stylesheet: %s", SvPV_nolen(ERRSV) );
}
}
if (real_dom->type == XML_HTML_DOCUMENT_NODE) {