Skip to content

fix(cli): resume caught JSON input errors at the next line - #321

Draft
owenshen0907 wants to merge 1 commit into
itchyny:mainfrom
owenshen0907:codex/fix-json-input-recovery-264
Draft

owenshen0907 wants to merge 1 commit into
itchyny:mainfrom
owenshen0907:codex/fix-json-input-recovery-264

Conversation

@owenshen0907

Copy link
Copy Markdown

After inputs returns a JSON syntax error, the decoder stays in its failed state. A query that catches that error cannot read the following valid line. The example in #264 consequently returns only the error length.

Allow subsequent explicit input/inputs calls to discard the remainder of the failed line and resume from the next one, retaining decoder read-ahead. Keep error offsets and line context correct across recovery and bound the retained diagnostic buffer. Ordinary CLI input processing keeps its existing stopping behavior for the failed input.

Validation:

  • New iterator and CLI regressions fail on the original implementation and pass with the fix
  • Covers CRLF, errors at a newline, repeated errors, read-ahead, exact numeric values, I/O errors, close behavior and multiple files
  • 4,000 malformed lines verify the buffer bound and final error location
  • go test -race -count=1 ./...
  • go vet ./..., staticcheck -checks all,-ST1000 -tags gojq_debug ./..., build, goimports and git diff --check
  • The built CLI matches jq 1.7.1 output and exit status for five caught/uncaught error scenarios; the original issue query now also returns the final 3

Tested on macOS arm64 with Go 1.26.3. Other OS/toolchain matrix jobs are left to CI.

Fixes #264

Base: 2bef47f

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.

error-handling discrepancy when reading mal-formed JSON

1 participant