feat: aggregate libxml2 errors into a single exception #3257
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.
What problem is this PR intended to solve?
In places (like document parsing) where it's possible for libxml2 to emit multiple warnings and errors, aggregate these libxml2 errors into a single exception so users can see all the problems.
Previously, we were grabbing the most recent "error" which might just be a warning and not the fatal error preventing parsing from completing. This was misleading and hid the source of the real problem.
Now, if there are multiple errors, they're aggregated into a single Nokogiri::XML::SyntaxError with a message like:
Note that I've also renamed some internal C functions to try to incrementally get consistent with naming.
Closes #2562
Have you included adequate test coverage?
Yes.
Does this change affect the behavior of either the C or the Java implementations?
It's a cosmetic improvement on the behavior of the CRuby XML and HTML4 parser.
I have not made this improvement to the JRuby implementation, but it should be easy enough to add if someone wishes to do the work.