Repository navigation
fix: print errors to stderr when --json flag is used - #807
Merged
joaopapereira merged 2 commits intoOct 30, 2026
Merged
Conversation
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 <yash.lunawat@rtp.vc>
Yash121l
force-pushed
the
fix/json-flag-error-output
branch
from
October 22, 2026 07:42
9a3ddea to
0852763
Compare
Windows reports a missing file as GetFileAttributesEx, not lstat, so check the prefix and the path instead of the exact message. Signed-off-by: Yash Lunawat <yash.lunawat@rtp.vc>
Contributor
Author
|
Thanks @joaopapereira. The Windows failure was my test: it matched the Linux |
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 #631
When a command fails and
--jsonis set, imgpkg exits 1 and prints nothing. For example,imgpkg push -b localhost:1/x/y:v1 -f missing-dir --jsongives empty stdout and stderr.maincalledos.Exit(1)right after writing the error to the UI.os.Exitskips deferred calls, soconfUI.Flush()never ran. The JSON UI buffers every line untilFlush, so the error was dropped. The plain-text UI writes right away, which is why this only happens with--json.This follows the fix for the same bug in kbld (carvel-dev/kbld#600).
mainnow keeps the parsed options so it can checkUIFlags.JSON. In JSON mode a failure writes a plain-textimgpkg: Error: ...line to stderr and leaves stdout empty, with exit code 1. Errors without--jsonstill go through the configured UI, and successful JSON output is unchanged.The new e2e test
TestPushWithJSONFlagPrintsErrorToStderrpushes a missing directory with--jsonand checks the exit error, empty stdout, and the exact stderr line. It fails ondevelop(stderr is empty) and passes with this change. It fails before any registry call, so it needs no registry.go vet,gofmtand golangci-lint v2.14.0 are clean.