Expected Behavior
When a top-level command fails (e.g. an unknown command or a bad global flag), the error should be printed once, to stderr, and the process should exit with the conventional failure code 1.
Actual Behavior
cmd.Execute() prints the error a second time to stdout and exits with -1 (which surfaces as 255):
|
if err := RootCmd.Execute(); err != nil { |
|
fmt.Println(err) |
|
os.Exit(-1) |
|
} |
RootCmd sets neither SilenceErrors nor SilenceUsage, so cobra already prints the error and usage hint to stderr. The extra fmt.Println(err) therefore duplicates the message onto stdout, and os.Exit(-1) yields a non-standard exit code.
Observed (splitting the streams):
$ dapr boguscmd 1>/tmp/out 2>/tmp/err ; echo "exit=$?"
exit=255
$ cat /tmp/out
unknown command "boguscmd" for "dapr" # ← leaked onto stdout
$ cat /tmp/err
Error: unknown command "boguscmd" for "dapr" # ← cobra's own message
Run 'dapr --help' for usage.
So dapr <typo> | some-parser feeds the error text into the pipe, and scripts checking for exit code 1 see 255.
Steps to Reproduce the Problem
- Run any unknown command, e.g.
dapr boguscmd, redirecting stdout somewhere: dapr boguscmd 1>/tmp/out.
- See the error appears in
/tmp/out (stdout) in addition to the terminal (stderr).
echo $? shows 255 rather than 1.
I have a fix ready and will open a PR right after filing this.
Release Note
RELEASE NOTE: FIX the Dapr CLI no longer duplicates top-level command errors onto stdout and now exits with code 1 instead of 255 on failure.
Expected Behavior
When a top-level command fails (e.g. an unknown command or a bad global flag), the error should be printed once, to stderr, and the process should exit with the conventional failure code
1.Actual Behavior
cmd.Execute()prints the error a second time to stdout and exits with-1(which surfaces as255):cli/cmd/dapr.go
Lines 80 to 83 in 96dd71a
RootCmdsets neitherSilenceErrorsnorSilenceUsage, so cobra already prints the error and usage hint to stderr. The extrafmt.Println(err)therefore duplicates the message onto stdout, andos.Exit(-1)yields a non-standard exit code.Observed (splitting the streams):
So
dapr <typo> | some-parserfeeds the error text into the pipe, and scripts checking for exit code1see255.Steps to Reproduce the Problem
dapr boguscmd, redirecting stdout somewhere:dapr boguscmd 1>/tmp/out./tmp/out(stdout) in addition to the terminal (stderr).echo $?shows255rather than1.I have a fix ready and will open a PR right after filing this.
Release Note
RELEASE NOTE: FIX the Dapr CLI no longer duplicates top-level command errors onto stdout and now exits with code 1 instead of 255 on failure.