Add JSON::ParserError#json_path - #1062
Conversation
|
Code looks great, I'll merge it soon.
No I think this was the good call. I might even change it for the
Hum, I need to check this a bit deeper, because in theory
Yep, I like that.
Yes, adding position and json_path to the Java parser would be welcome in a followup. |
b04624e to
fbd308c
Compare
fbd308c to
c9bd21b
Compare
I forced push your branch with an extra I think we should just not build the path it if a Hash key isn't a String/Symbol or an array index isn't an Integer. |
|
Went with your first suggestion: the path stops at the first key that isn't a String or Symbol, so the valid prefix is kept ( |
| if (plain) { | ||
| rb_str_cat_cstr(path, "."); | ||
| rb_str_cat(path, RSTRING_PTR(key), len); | ||
| return true; | ||
| } |
There was a problem hiding this comment.
I just had the realization that it would probably be simpler to just push the raw objects in an array, and build the json_path string in Ruby. That would also help share the code with the eventual JRuby version.
This isn't a performance sensitive path, and that logic can be shared with the eventual JRuby implementation.
d77424e to
8550be8
Compare
Implements the
ParserError#json_pathidea from #954: a JSONPath-style string locating a parse error in the document.The path is reconstructed lazily at raise time: the frame stack still holds every enclosing container at that point and their keys are still on the rvalue stack, so nothing is added to the happy path.
benchmark/parser.rbbefore/after shows no difference outside noise.A few choices worth reviewing:
$.x.a) rather than the containing object, which seemed closer to what the reporter needs. Line/column keep pointing at the object's opening brace, so the two diverge slightly there. Happy to make it point at the object instead if you'd rather keep them consistent.$["hello world"],$["a\"b"].symbolize_namesandon_load-transformed keys are handled.ResumableParser, where line/column can't be accurate: an error raised mid-feed still reports the exact path.cParser_parsereleased the spilled stacks before raising the end-of-input error. That was fine while nothing read parser state during the raise, but the path reconstruction does (the 100k-deep minefield fixture segfaulted), so the raise now happens before the release. The existing comment already documents that skipping the release on the exception path doesn't leak.json_pathreturns nil there likeline/columndo. Can look at that as a follow-up if there's interest.Closes #954