Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate output - probably in error cases #1415

Closed
jensklose opened this issue Jun 9, 2021 · 3 comments · Fixed by #1463
Closed

Duplicate output - probably in error cases #1415

jensklose opened this issue Jun 9, 2021 · 3 comments · Fixed by #1463

Comments

@jensklose
Copy link

Versions

go version go1.16.4 linux/amd64
cobra 1.1.3

How to reproduce?

Generate a new project with cobra init --pkg-name doublecheck.
Generate a new command with cobra add version.
Build the project or use go run.

Output

>go run main.go version
version called
> go run main.go vrsion
Error: unknown command "vrsion" for "doublecheck"

Did you mean this?
        version

Run 'doublecheck --help' for usage.
Error: unknown command "vrsion" for "doublecheck"

Did you mean this?
        version

exit status 1

Test with unknown command:

go run main.go foo
Error: unknown command "foo" for "doublecheck"
Run 'terrasec --help' for usage.
Error: unknown command "foo" for "doublecheck"
exit status 1

Expected behavior

No double messages

@afbagwell
Copy link

afbagwell commented Jul 22, 2021

We are observing this behavior as well with a bare-bones setup for a new CLI app my team is working on.

using
go1.15.12 linux/amd64
cobra 1.2.1

More info:
Duplication is occurring not only on typos as reported above but also if RunE throws an error. The pattern is similar:

Error: [error msg]

[Usage info]

[error msg]

It's as if whatever method or template is being used in both cases is accidentally calling the error string a second time.

@ANGkeith
Copy link
Contributor

ANGkeith commented Jul 25, 2021

func Execute() {
	cobra.CheckErr(rootCmd.Execute())
}

removing the cobra.CheckErr() fix the duplicated error message for me

func Execute() {
	rootCmd.Execute()
}

resulting in:

Error: [error msg]
[Usage info]

but the program exits with status code 0, and i use this to fix reflect the correct exit status code

func Execute() {
	err := rootCmd.Execute()
	if err != nil {
		os.Exit(1)
	}
}

@github-actions
Copy link

This issue is being marked as stale due to a long period of inactivity

flrnd added a commit to flrnd/cfm.sh that referenced this issue Apr 6, 2022
If error then return. This fix two things, one, a duplicate unknown
command (see this spf13/cobra#1415), second,
unnecesary exit(1) on command line
flrnd added a commit to flrnd/cfm.sh that referenced this issue Apr 6, 2022
* Switch back to cobra

* Replace coral with cobra

* Remove Log.Panic

If error then return. This fix two things, one, a duplicate unknown
command (see this spf13/cobra#1415), second,
unnecesary exit(1) on command line
flrnd added a commit to flrnd/gobatmon that referenced this issue Apr 6, 2022
flrnd added a commit to flrnd/gobatmon that referenced this issue Apr 6, 2022
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 a pull request may close this issue.

3 participants