Permalink
Browse files

Describe XSLT parser errors in the exception message instead of using…

… rb_warn

All XSLT parser errors will be displayed in the exception message.

When we did an rb_raise from the callback, we only got the first parser error.
A nice side effect here is that we get all errors in the exception.
  • Loading branch information...
ender672 committed Jul 28, 2011
1 parent 2115a76 commit 953e9b3b1ecf240c83c544f185461c7b86d387d5
Showing with 6 additions and 6 deletions.
  1. +6 −3 ext/nokogiri/xslt_stylesheet.c
  2. +0 −3 test/test_xslt_transforms.rb
@@ -26,7 +26,7 @@ static void xslt_generic_error_handler(void * ctx, const char *msg, ...)
vasprintf(&message, msg, args);
va_end(args);
- rb_warning("%s", message);
+ rb_str_cat2((VALUE)ctx, message);
vasprintf_free(message);
}
@@ -40,11 +40,13 @@ static void xslt_generic_error_handler(void * ctx, const char *msg, ...)
static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj)
{
xmlDocPtr xml, xml_cpy;
+ VALUE errstr, exception;
xsltStylesheetPtr ss ;
Data_Get_Struct(xmldocobj, xmlDoc, xml);
exsltRegisterAll();
- xsltSetGenericErrorFunc(NULL, xslt_generic_error_handler);
+ errstr = rb_str_new(0, 0);
+ xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
xml_cpy = xmlCopyDoc(xml, 1); /* 1 => recursive */
ss = xsltParseStylesheetDoc(xml_cpy);
@@ -53,7 +55,8 @@ static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj)
if (!ss) {
xmlFreeDoc(xml_cpy);
- rb_raise(rb_eRuntimeError, "Unable to Parse the XSLT Document.");
+ exception = rb_exc_new3(rb_eRuntimeError, errstr);
+ rb_exc_raise(exception);
}
return Data_Wrap_Struct(klass, NULL, dealloc, ss);
@@ -175,10 +175,7 @@ def test_xslt_parse_error
</xsl:template>
</xsl:stylesheet>}
EOX
- old_verbose = $VERBOSE
- $VERBOSE = false
assert_raises(RuntimeError) { Nokogiri::XSLT.parse(xslt_str) }
- $VERBOSE = old_verbose
end
def test_passing_a_non_document_to_transform

0 comments on commit 953e9b3

Please sign in to comment.