Skip to content
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

feat: aggregate libxml2 errors into a single exception #3257

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

flavorjones
Copy link
Member

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:

Multiple errors encountered:
WARNING: text of warning message
ERROR: text of error message
WARNING: text of second warning message

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.

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:

    Multiple errors encountered:
    WARNING: text of warning message
    ERROR: text of error message
    WARNING: text of second warning message

Note that I've also renamed some internal C functions to try to
incrementally get consistent with naming.

Closes #2562
@flavorjones flavorjones added this to the v1.17.0 milestone Jun 24, 2024
@flavorjones flavorjones merged commit 6cb7f0f into main Jun 24, 2024
132 checks passed
@flavorjones flavorjones deleted the flavorjones-aggregate-errors branch June 24, 2024 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] xinclude error message is shadowed by missing DTD warning message.
1 participant