New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix xslt error parsing so filename and line numbers show. #206

Merged
merged 1 commit into from Sep 16, 2016

Conversation

Projects
None yet
2 participants
@lambdafu
Copy link
Contributor

lambdafu commented Sep 15, 2016

This is worth a :facepalm: ...

Before:

<string>:0:0:ERROR:XSLT:ERR_OK: compilation error, element 'foo'
<string>:0:0:ERROR:XSLT:ERR_OK: xsltStylePreCompute: unknown xsl:foo
<string>:0:0:ERROR:XSLT:ERR_OK: compilation error, element 'foo'
<string>:0:0:ERROR:XSLT:ERR_OK: xsltParseStylesheetTop: unknown foo element

After:

errtest.xml:3:0:ERROR:XSLT:ERR_OK: compilation error, element 'foo'
<string>:0:0:ERROR:XSLT:ERR_OK: xsltStylePreCompute: unknown xsl:foo
errtest.xml:3:0:ERROR:XSLT:ERR_OK: compilation error, element 'foo'
<string>:0:0:ERROR:XSLT:ERR_OK: xsltParseStylesheetTop: unknown foo element

We can't do better, as the second line in the two errors embellishes the first line and does not duplicate the file/line info.

Example:

from io import BytesIO
from lxml import etree
style = etree.parse("errtest.xml")
try:
    etree.XSLT(style)
except etree.XSLTParseError as e:
    print e.error_log
@lambdafu

This comment has been minimized.

Copy link
Contributor Author

lambdafu commented Sep 15, 2016

Oh, here is the xslt:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:foo />
</xsl:stylesheet>

It's really the same from the test case that's already there (but which only checks for presence of ERROR:XSLT).

@scoder

This comment has been minimized.

Copy link
Member

scoder commented Sep 16, 2016

Ah, beautiful. Thanks!

@scoder scoder merged commit 9113dc1 into lxml:master Sep 16, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment