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

Throw a more specific error for an empty document #1448

Closed
newellista opened this issue Mar 23, 2016 · 3 comments
Closed

Throw a more specific error for an empty document #1448

newellista opened this issue Mar 23, 2016 · 3 comments

Comments

@newellista
Copy link

When an empty document gets returned, would it be possible to throw a more specific error?

The current code (https://github.com/sparklemotion/nokogiri/blob/master/ext/java/nokogiri/XmlSaxParserContext.java#L263-L264) throws a RuntimeError. Could you return something like EmptyDocumentError < RuntimeError?

We are occasionally running into a problem, where our upstream API provider is sending an empty XML document. Rather than rescuing RuntimeError and then parsing the error message, it would be more idiomatic to be able to rescue something like EmptyDocumentError.

@flavorjones
Copy link
Member

I'd prefer to raise a SyntaxError, as we've standardized the XML DOM strict parsing on MRI and JRuby to do this (see #1005 for details).

I think that will have to suffice, since I don't believe the SAX parser errors differentiate between an empty document and a set of other invalid-document errors.

Objections to that solution?

@newellista
Copy link
Author

I suppose that works. My main objection is to RuntimeError, so this would certainly be an improvement!

I see the commit that implements this. Is it scheduled for release soon?

Thanks for the reply/consideration!

@flavorjones
Copy link
Member

I think this was fixed in commit aece1ef which was in 1.6.8.

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

No branches or pull requests

2 participants