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

Feature: Allow a Yajl::Parser to be closed. #131

Open
yaauie opened this issue Feb 6, 2014 · 0 comments
Open

Feature: Allow a Yajl::Parser to be closed. #131

yaauie opened this issue Feb 6, 2014 · 0 comments

Comments

@yaauie
Copy link

yaauie commented Feb 6, 2014

I've hit a bug in a production scenario in which an upstream provider supplies a truncated JSON stream. The connection drops, and we have no way to know that we have partial data, and no way to request the data again. Since this is fairly normal (the expectation being that it will be called again with a continuation from where it left off) and not a failure scenario, the ability to make it a failure scenario would be very helpful.

The following is the rough API I would envision:

p = Yajl::Parser.new
# => #<Yajl::Parser:0x007fa60bae56d8>
p.parse(truncated_json)
# => nil
p.closed?
# => false
p.close
# ! raised ParseError: buffer remaining.
# If possible, include buffer or state representation in exception message
p.closed?
# => true
p.parse(remainder)
# ! raised ParseError: buffer closed. 

This will help with issues like #123, #58, and expectations set for JSON-gem compatibility (even though you plan to drop it in 2.x)

If you have strong opinions for or against, I would appreciate them before I begin the work.

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

1 participant