Do not duplicate top-level command errors onto stdout; exit 1 not 255#1678
Open
Mukuwul wants to merge 1 commit into
Open
Do not duplicate top-level command errors onto stdout; exit 1 not 255#1678Mukuwul wants to merge 1 commit into
Mukuwul wants to merge 1 commit into
Conversation
cmd.Execute printed the command error a second time to stdout via fmt.Println and exited with -1 (which surfaces as 255). RootCmd sets neither SilenceErrors nor SilenceUsage, so cobra already prints the error and usage hint to stderr; the extra print leaked a duplicate onto stdout, corrupting piped output for mistyped commands. Drop the extra print and exit with the conventional failure code 1. Signed-off-by: Mukul <nmukul32@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1678 +/- ##
==========================================
+ Coverage 15.57% 16.93% +1.36%
==========================================
Files 64 65 +1
Lines 7244 7323 +79
==========================================
+ Hits 1128 1240 +112
+ Misses 6028 5995 -33
Partials 88 88 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Description
cmd.Execute()printed the top-level command error a second time to stdout and exited with-1(which surfaces as255):RootCmdsets neitherSilenceErrorsnorSilenceUsage, so cobra already prints the error and usage hint to stderr. The extrafmt.Println(err)leaked a duplicate copy onto stdout, sodapr <typo> | some-parserfed the error text into the pipe.This PR drops the duplicate print (cobra keeps handling stderr) and exits
1.Verified by splitting the streams:
Issue reference
Fixes #1677
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list: