Skip to content

Fix error output in JSON mode - #600

Merged
joaopapereira merged 2 commits into
carvel-dev:developfrom
snowyukitty:fix/json-error-output
Oct 2, 2026
Merged

joaopapereira merged 2 commits into
carvel-dev:developfrom
snowyukitty:fix/json-error-output

Conversation

@snowyukitty

@snowyukitty snowyukitty commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #455.

When --json is enabled, fatal errors are buffered by the JSON UI. The process then calls os.Exit(1), which skips the deferred flush and leaves users with a non-zero exit code but no diagnostic. Flushing the buffer on this path would put the error on stdout, while JSON failures are expected to keep stdout empty and report a plain-text error on stderr.

This change keeps the parsed UI options available in main and bypasses the buffered UI only for JSON-mode failures. Non-JSON errors still use the configured UI, preserving color and TTY behavior; successful JSON output is unchanged.

An end-to-end regression test verifies exit code 1, empty stdout, and a plain-text stderr diagnostic.

Write fatal errors directly to stderr when JSON output is enabled so
os.Exit does not discard the buffered message. Keep stdout empty and
preserve the configured UI for non-JSON errors.

Add a subprocess regression test covering streams and exit status.

Fixes carvel-dev#455

Signed-off-by: snowyukitty <[email protected]>

@joaopapereira joaopapereira left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am going to allow the tests to run, nevertheless I left a comment but in general the code looks ok

Comment thread cmd/kbld/kbld_test.go Resolved
@github-project-automation github-project-automation Bot moved this to In Progress in Carvel Aug 13, 2026

@joaopapereira joaopapereira left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@joaopapereira
joaopapereira merged commit bdb1e62 into carvel-dev:develop Oct 2, 2026
6 checks passed
Yash121l added a commit to Yash121l/imgpkg that referenced this pull request Oct 22, 2026
main called os.Exit(1) right after writing the error to the UI, which
skipped the deferred confUI.Flush(). The JSON UI buffers every line until
Flush, so a failing command run with --json exited 1 and printed nothing.

In JSON mode, write the error as plain text to stderr and keep stdout
empty, matching kbld (carvel-dev/kbld#600). Non-JSON errors still go
through the configured UI.

Fixes carvel-dev#631

Signed-off-by: Yash Lunawat <[email protected]>

This branch was previously deployed

1 inactive deployment
DockerHub E2E — 90137df5 Deployed Aug 21, 2026 by snowyukitty via Test GH #1500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

kbld with flag --json swallows error

2 participants