Skip to content

Do not duplicate top-level command errors onto stdout; exit 1 not 255#1678

Open
Mukuwul wants to merge 1 commit into
dapr:masterfrom
Mukuwul:fix/root-command-error-output
Open

Do not duplicate top-level command errors onto stdout; exit 1 not 255#1678
Mukuwul wants to merge 1 commit into
dapr:masterfrom
Mukuwul:fix/root-command-error-output

Conversation

@Mukuwul

@Mukuwul Mukuwul commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Description

cmd.Execute() printed the top-level command error a second time to stdout and exited with -1 (which surfaces as 255):

if err := RootCmd.Execute(); err != nil {
    fmt.Println(err)   // duplicate, on stdout
    os.Exit(-1)        // 255
}

RootCmd sets neither SilenceErrors nor SilenceUsage, so cobra already prints the error and usage hint to stderr. The extra fmt.Println(err) leaked a duplicate copy onto stdout, so dapr <typo> | some-parser fed the error text into the pipe.

This PR drops the duplicate print (cobra keeps handling stderr) and exits 1.

Verified by splitting the streams:

# before
$ dapr boguscmd 1>/tmp/out 2>/tmp/err ; echo $?
255
$ cat /tmp/out
unknown command "boguscmd" for "dapr"       # leaked onto stdout

# after
$ dapr boguscmd 1>/tmp/out 2>/tmp/err ; echo $?
1
$ cat /tmp/out
                                            # empty
$ cat /tmp/err
Error: unknown command "boguscmd" for "dapr"
Run 'dapr --help' for usage.

Issue reference

Fixes #1677

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests (n/a - top-level error plumbing, no unit-test seam)
  • Extended the documentation (n/a - behavior fix)

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

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 16.93%. Comparing base (6838be1) to head (2d66165).
⚠️ Report is 74 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Top-level command errors are duplicated onto stdout and exit code is 255 instead of 1

1 participant