Skip to content

[codex] jq: defer stdin reads for null input - #776

Merged
ewhauser merged 4 commits into
mainfrom
ewhauser/jq-null-input-iter
Mar 29, 2026
Merged

ewhauser merged 4 commits into
mainfrom
ewhauser/jq-null-input-iter

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Summary

  • make jq input loading lazy so jq -n does not consume stdin before the query actually requests input or inputs
  • preserve existing exit codes when deferred iterator setup fails
  • add regressions for the shell loop repro and deferred input behavior

Root Cause

The current jq implementation eagerly called readJQInputSources while building the iterator passed to gojq.WithInputIter. For jq -n, that meant stdin was consumed during setup even though the main query input had already been swapped to null. Inside while read ... done < <(...) loops, the eager read stole the next loop item from stdin and broke the Harness overlay example.

Impact

This restores expected jq -n behavior on main and unblocks the Harness overlay flow that shells out to jq while iterating lines from process substitution.

Validation

  • go test ./contrib/jq
  • replayed the Harness repro script under go run ./examples/harness-overlay --script ... in a disposable main-based worktree with the example cherry-picked
  • go test ./examples/harness-overlay in that disposable worktree

@ewhauser
ewhauser marked this pull request as ready for review March 28, 2026 23:54

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4ca22d872d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread contrib/jq/jq.go Resolved
@ewhauser

Copy link
Copy Markdown
Owner Author

Addressed in 793c12ed: missing input files now remain sticky exit-2 errors under jq -n, while unused file arguments stay lazy and try input catch ... can still emit its catch value. Added regressions for both cases in contrib/jq/jq_test.go.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 793c12ed53

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread contrib/jq/jq.go Resolved
@ewhauser

Copy link
Copy Markdown
Owner Author

Follow-up addressed in 05e13828: sticky source errors now take precedence over later query exit handling, so cases like jq -ne 'try input catch empty' missing.json still exit 2. Added a regression for that path in contrib/jq/jq_test.go.

@ewhauser
ewhauser merged commit 25a187c into main Mar 29, 2026
16 checks passed
@ewhauser
ewhauser deleted the ewhauser/jq-null-input-iter branch March 29, 2026 00:44
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.

1 participant