Skip to content

Report output separator write errors in the CLI - #351

Merged
itchyny merged 2 commits into
itchyny:mainfrom
pcbeingused33:fix/cli-output-separator-errors
Dec 1, 2026
Merged

itchyny merged 2 commits into
itchyny:mainfrom
pcbeingused33:fix/cli-output-separator-errors

Conversation

@pcbeingused33

@pcbeingused33 pcbeingused33 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

gojq checks errors when writing result values, but it discards errors when writing newline and NUL terminators or YAML document separators. This can leave output incomplete while the CLI exits successfully, for example when the file system fills up or the file size limit is reached exactly at the trailing newline.

Reproduction (1024-byte file size limit, output is 1024 bytes plus the newline):

bash -c 'ulimit -f 1; gojq -nr "\"x\" * 1024" > out'; echo "exit=$?"

Before: exit=0 and out is missing its trailing newline. After: gojq: write /dev/stdout: file too large and exit=5.

Return errors from all three separator writes through the existing CLI error path.

Ran go test ./cli.

AI assistance was used to prepare the patch.

Comment thread cli/cli_test.go Outdated
}

func (w separatorErrorWriter) Write(p []byte) (int, error) {
if string(p) == w.separator {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This looks very weird and unrealistic writer implementation. The diff in the implementation looks as is, unlikely to be reverted. Just drop this test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Dropped TestCliRunOutputSeparatorError and the helper writer. The implementation is unchanged.

This comment was drafted with Claude Code.

The review asked to remove the unrealistic writer. The
implementation is unchanged.
@itchyny
itchyny merged commit 3cd8942 into itchyny:main Dec 1, 2026
11 checks passed
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.

2 participants