Skip to content

Fix error output in JSON mode - #600

Open
snowyukitty wants to merge 2 commits into
carvel-dev:developfrom
snowyukitty:fix/json-error-output
Open

Fix error output in JSON mode#600
snowyukitty wants to merge 2 commits into
carvel-dev:developfrom
snowyukitty:fix/json-error-output

Conversation

@snowyukitty

@snowyukitty snowyukitty commented Jul 20, 2026

Copy link
Copy Markdown

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 <270071858+snowyukitty@users.noreply.github.com>

@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 Outdated
@github-project-automation github-project-automation Bot moved this to In Progress in Carvel Aug 13, 2026
Signed-off-by: snowyukitty <270071858+snowyukitty@users.noreply.github.com>
@snowyukitty
snowyukitty deployed to DockerHub E2E August 21, 2026 02:25 — with GitHub Actions Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

kbld with flag --json swallows error

3 participants