Repository navigation
fix(cli): print each error once - #44
Merged
Merged
Conversation
Cobra printed the "Error: ..." line when a command returned and main printed the same message again, so a single failure was reported twice. Silence cobra's reporting and keep main as the only printer. Main runs after the background update check has finished writing to stderr, so the error stays the last line the user sees. It keeps the "Error: " prefix, which separates a failure from the progress and warning output atb also writes to stderr. Extract run() from main so the exit path can be tested.
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.
Every error from
atbreached the user twice.internal/cli/root.gosetSilenceUsagebut notSilenceErrors, so cobraprinted the
Error: ...line when the command returned, andcmd/atb/main.goprinted the same message again. One failure looked like two. It affected every
error path, not one command.
The fix
Silence cobra's reporting and leave
mainas the only printer.The alternative - dropping main's print and letting cobra report - puts the
error before
WaitForUpdateCheck()runs, and that check also writes tostderr, so a failure could end up buried above the update banner. Printing from
main keeps the error as the last line. It keeps the
Error:prefix, whichmatters because
atbwrites progress and warnings to stderr too; without aprefix a bare error line is indistinguishable from
Resolved 99 run accession(s)....run()is extracted frommain()so the exit path is testable. Behavior ofmainis otherwise unchanged.After
Verification
cmd/atb/main_test.go, written first and watched fail(
error reported 2 time(s), want 1).cmd/atbwas previously untested, sothe suite goes from 21 to 22 covered packages.
run accession, unknown flag, unknown command - each prints once and exits 1.
Unknown-command takes a different cobra branch, so it is covered separately.
stderr; only error output changed.
go vetclean,gofmtclean on the touched files,make docsproduces nodiff.