-
Notifications
You must be signed in to change notification settings - Fork 861
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
Improve JSON decoder errors (#4076) #4079
Conversation
} | ||
} | ||
|
||
/// Returns the number of rows | ||
pub fn num_rows(&self) -> usize { | ||
self.num_rows | ||
} | ||
|
||
/// Serialize the tape element at index `idx` to `out` returning the next field index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is worth noting that this necessarily cannot preserve whitespace, but it at least preserves structure
This does not appear to materially impact the performance benchmarks |
arrow-json/src/reader/tape.rs
Outdated
/// Return an error containing the [`TapeElement`] at `cur_idx` if it | ||
/// is not the start of a field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Return an error containing the [`TapeElement`] at `cur_idx` if it | |
/// is not the start of a field | |
/// Return an error containing at `cur_idx` if it | |
/// is not the start of a field |
let err = parse_err(r#"{"a": 123}"#); | ||
assert_eq!( | ||
err, | ||
"Json error: whilst decoding field 'a': expected { got 123" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Which issue does this PR close?
Closes #4076
Rationale for this change
This improves the error messages when decoding the tape, these are produced when the JSON input is valid, i.e. has successfully been decoded to a tape, but doesn't match the expected schema. Producing a more helpful error message is therefore useful for identifying what has gone wrong.
Unfortunately at this level rows don't really exist, but at the very least we can provide more context than a single byte 😅
The error messages for invalid JSON are still not brilliant, but given JSON validation is not "specialized", I'm not sure how important this is.
What changes are included in this PR?
Are there any user-facing changes?