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

Improve JSON decoder errors (#4076) #4079

Merged
merged 3 commits into from
Apr 13, 2023

Conversation

tustvold
Copy link
Contributor

@tustvold tustvold commented Apr 13, 2023

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?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Apr 13, 2023
}
}

/// 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
Copy link
Contributor Author

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

@tustvold
Copy link
Contributor Author

This does not appear to materially impact the performance benchmarks

Comment on lines 100 to 101
/// Return an error containing the [`TapeElement`] at `cur_idx` if it
/// is not the start of a field
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@tustvold tustvold merged commit 0121cdf into apache:master Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better JSON Reader Error Messages
2 participants