skupper icon indicating copy to clipboard operation
skupper copied to clipboard

skupper completion subcommand throws errors into stdout

Open hash-d opened this issue 7 months ago • 3 comments

Describe the bug

On failure, the completion subcommand prints the error and usage to stdout, instead of stderr.

It also does not return a non-zero exit code.

How To Reproduce

Just issue an invalid completion command, such as missing the shell specification

$ skupper completion 2> /dev/null
Generate the autocompletion script for skupper for the specified shell.
See each sub-command's help for details on how to use the generated script.

Usage:
  skupper completion [command]

Available Commands:
  bash        Generate the autocompletion script for bash
  fish        Generate the autocompletion script for fish
  powershell  Generate the autocompletion script for powershell
  zsh         Generate the autocompletion script for zsh

Flags:
  -h, --help   help for completion

Global Flags:
  -c, --context string      Set the kubeconfig context
      --kubeconfig string   Path to the kubeconfig file to use
  -n, --namespace string    Set the namespace
  -p, --platform string     Set the platform type to use [kubernetes, podman, docker, linux]

Use "skupper completion [command] --help" for more information about a command.
$ echo $?
0

Expected behavior

The error message should go to stderr. This is specially important for this subcommand, as its output is consumed by the shell.

The exit code should be non-zero, too, in case of failures.

Environment details

  • Skupper CLI: 2.0
  • Skupper Operator (if applicable): N/A
  • Platform: N/A

Additional context Add any other context about the problem here.

hash-d avatar May 20 '25 13:05 hash-d

Checked and confirmed this is still the case for the code currently in main.

hash-d avatar May 21 '25 12:05 hash-d

@hash-d not positive I understand the importance here, but perhaps this should be a bug/suggestion over in https://github.com/spf13/cobra?

c-kruse avatar Sep 19 '25 22:09 c-kruse

@c-kruse, Cobra went back and forth on it a bit:

  • https://github.com/spf13/cobra/issues/1002
  • https://github.com/spf13/cobra/issues/2186

Reason I opened the ticket was twofold:

  • Current behavior is non-standard (error output going to stdout, and exit status being 0 despite an error)
  • It was bugging my .bashrc, as I go back and forth between 1.x and 2.x, and the command behave differently between the versions (1.x expects no argument, always dumps bash code)

The error output going to stdout then was consumed by the shell (expecting bash instructions) and generated some cryptic errors.

The scenario is probably not something that would be seen with actual users often (as opposed to devs and testers like myself), so it's not a priority. It's definitely not worth it to reimplement the completion command just because of this.

Still, it annoys me whenever any command does not report its return code correctly, or sends error output to stdout, especially when normal stdout is expected to be consumed by another program :)

hash-d avatar Oct 09 '25 20:10 hash-d