Skip to content

Commit

Permalink
Describe XSLT parser errors in the exception message instead of using…
Browse files Browse the repository at this point in the history
… 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 953e9b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 6 additions & 3 deletions ext/nokogiri/xslt_stylesheet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions test/test_xslt_transforms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 953e9b3

Please sign in to comment.