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

jsonio: Fix parse errors on EOF #5055

Merged
merged 2 commits into from
Feb 29, 2024
Merged

jsonio: Fix parse errors on EOF #5055

merged 2 commits into from
Feb 29, 2024

Conversation

mattnibs
Copy link
Collaborator

Fix an issue with jsonio.Reader where parse errors occurring at the end of an input (EOF) are often ignored or return an ambiguous EOF error.

Fix an issue with jsonio.Reader where parse errors occurring at the end
of an input (EOF) are often ignored or return an ambiguous EOF error.
@mattnibs mattnibs requested a review from a team February 29, 2024 16:06
@philrz
Copy link
Contributor

philrz commented Feb 29, 2024

@mattnibs: The description of the fix reminded me of a familiar bug, so I dug up #4537. Indeed, it seems to improve the error message in one of the cases described there. Whereas it looks like this on tip of main:

$ zq -version
Version: v1.14.0-6-g87deeebe

$ zq -z lines-10.ndjson
lines-10.ndjson: EOF

On your branch at commit 1d3d2c3 it's now improved to:

$ zq -version
Version: v1.14.0-7-g1d3d2c37

$ zq -z lines-10.ndjson
lines-10.ndjson: unexpected end of JSON input

FWIW, the other case shown there isn't affected.

$ zq -version
Version: v1.14.0-6-g87deeebe

$ zq -z lines-9.ndjson
lines-9.ndjson: parse error: string literal: unescaped line break

$ zq -version
Version: v1.14.0-7-g1d3d2c37

$ zq -z lines-9.ndjson
lines-9.ndjson: parse error: string literal: unescaped line break

Since you've just spent time under the hood looking at this code, maybe you'd like to make an assessment of whether unescaped line break is the best we're ever going to do for that case or if there's an opportunity to improve on that as well, such that we could declare victory on that whole issue.

@mattnibs
Copy link
Collaborator Author

@philrz this is a separate issue since in the example of lines-9.ndjson zq is choosing the zsonio reader which is where the error is coming from. On this branch if I run it with the json reader specified (which is what this pr addresses) I get the expected error message:

$ zq -i json lines-9.ndjson
lines-9.ndjson: unexpected end of JSON input

@mattnibs mattnibs merged commit 36b0d26 into main Feb 29, 2024
3 checks passed
@mattnibs mattnibs deleted the jsonio-parse-error-eof branch February 29, 2024 20:54
@philrz philrz linked an issue Mar 13, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent errors when reading NDJSON with bad last line
3 participants