Fix error output in JSON mode - #600
Open
snowyukitty wants to merge 2 commits into
Open
Conversation
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
requested changes
Aug 13, 2026
joaopapereira
left a comment
Member
There was a problem hiding this comment.
I am going to allow the tests to run, nevertheless I left a comment but in general the code looks ok
snowyukitty
temporarily deployed
to
DockerHub E2E
August 13, 2026 23:01 — with
GitHub Actions
Inactive
Signed-off-by: snowyukitty <270071858+snowyukitty@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #455.
When
--jsonis enabled, fatal errors are buffered by the JSON UI. The process then callsos.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
mainand 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.