Skip to content

JSON::ResumableParser swallows ParserError raised in on_load #1024

@mame

Description

@mame

ResumableParser#parse swallows a JSON::ParserError raised inside on_load.

require "json"
parser = JSON::ResumableParser.new(on_load: ->(o) do
  JSON.parse("") #=> raises JSON::ParserError
  o
end)
parser << "[1]"
parser.parse
# expected: raises JSON::ParserError
# actual:   parse returns false (the error is swallowed)

This happens because the current implementation wraps parsing in rb_protect. Could exceptions raised inside on_load be re-raised? I'm a bit concerned about the overhead, though. If we do not, it would be good to document the behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions