Skip to content

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

Description

@Mukuwul

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):

cli/cmd/dapr.go

Lines 80 to 83 in 96dd71a

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

  1. Run any unknown command, e.g. dapr boguscmd, redirecting stdout somewhere: dapr boguscmd 1>/tmp/out.
  2. See the error appears in /tmp/out (stdout) in addition to the terminal (stderr).
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions