Improve XML parse error reporting#2420
Merged
Merged
Conversation
plajjan
reviewed
Aug 12, 2025
Use xmlGetLastError() to get the last error from libxml2. Strip trailing whitespace from the message if present. Suppres verbose output from libxml2 on stderr with the XML_PARSE_NOERROR option.
8f345e7 to
31dd5f6
Compare
plajjan
approved these changes
Aug 14, 2025
plajjan
left a comment
Contributor
There was a problem hiding this comment.
I trust that this works. Consider taking the opportunity to change the error type to something better and perhaps add a test case or two (that would go in tests/stdlib_tests/src/test_xml.xml).
Feel free to merge. If you want to merge as-is, that's OK. If you want to add the test and / or change exception type, that's OK too.
plajjan
reviewed
Aug 18, 2025
plajjan
reviewed
Aug 18, 2025
The XmlParseError base exception is ValueError, but it includes more context information about the error location.
7128966 to
d2ba418
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use xmlGetLastError() to get the last error from libxml2. Strip trailing whitespace from the message if present.
We already get more verbose output from libxml2 on stderr, but this allows us to pass at least some hints about what went wrong via an exception.