Skip to content

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

Open
@yaauie

Description

@yaauie

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions