Repository navigation
Show the line and context for an error at the end of the input - #3122
Open
Kuriyeatsuchi wants to merge 3 commits into
Open
Kuriyeatsuchi wants to merge 3 commits into
Kuriyeatsuchi wants to merge 3 commits into
Conversation
format_error printed only "index N" when the error position was the end of the buffer. That is where a truncated document or a missing closing bracket fails, and where the YAML reader reports some type mismatches (issue stephenberry#3067), so these common errors came without a line, column or context. Point just past the last character that is not trailing whitespace instead, so the message shows the line where the input stops. The reported index is unchanged, and input that is empty or only whitespace still gets "index N". An error at a newline character also printed the following line as part of its context, which put the caret under the wrong text. The context now ends at that newline. The YAML missing key tests pinned the index-only output and now expect the line, column and context.
With GLZ_NULL_TERMINATED=false the reader reports unexpected_end for these inputs instead of expected_comma or expected_bracket, so the json_test_non_null build failed on the error code. The tests are about the line, column and context, so check those and not the code.
Owner
|
Thanks for this! I pushed 7e9f50b on top of it with these changes:
I also updated the description to match. The |
Contributor
Author
|
Thanks for the fixes, and for catching the binary buffer case! |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
glz::format_errorprinted onlyindex Nwhen the error position was the end of the buffer. That is where a truncated document or a missing closing bracket fails, so a common error came without a line, column or context:Now:
The caret goes just past the last character that is not trailing whitespace, so a file that ends in a newline gets the same message. The reported index is unchanged, and input that is empty or only whitespace still gets
index N.This also covers the "error does not contain line and context info" part of #3067, where the YAML reader reports
object: 42at the end of the input.Other changes to the context:
std::stringreaches the same text path. A line that contains control characters other than tab and CR is treated as binary, and only the index is reported, so a truncated binary buffer still givesindex N: unexpected_endinstead of printing raw bytes. The byte at the error is exempt: a raw control character in a JSON string is the error itself, so that message keeps its context and shows the character as a space.Tests:
json_testcovers errors at the end of the input, with trailing whitespace and on a CRLF line, an error at a newline, whitespace-only input, a control character at the error, and binary buffers.beve_testandcbor_testcheck that a truncated buffer gives only the index. The CBOR buffer contains no zero bytes.