-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Error message is shown twice. #304
Comments
Same happens with unknown flags for me. |
@dkumor @lukasma I found the problem. If you follow the example in readme or use cobra generator, you would have following code in your root command
comment out the if err != nil {
// If found parse to a subcommand and then failed, talk about the subcommand
if cmd != nil {
c = cmd
}
if !c.SilenceErrors {
c.Println("Error:", err.Error())
c.Printf("Run '%v --help' for usage.\n", c.CommandPath())
}
return c, err
} But I don't know if this is a special case, if cobra print all the error messages automatically, then we can remove the btw: I am also using Windows 10, but I think this issue is platform independent. |
- see spf13/cobra#304 and #44 - command might be a special case
Wow, thanks detective 👍 |
@at15 showed right solution. Closing it. |
* Switches context to newly created cluster by default, except if if --switch-context=false is passed. * If --artifact-directory is not passed, and ~/.kube/config file exists, the context is merged in the existing file. If ~/.kube/config doesn't exist, it creates it. * Sets SilenceUsage to true in kubeconfig root command, to avoid showing the usage message in the case of error. Relevant issue: spf13/cobra#340 * Removes printing of error in Execute() of kubeconfig command to avoid printing twice an error message. Relevant issue: spf13/cobra#304 Signed-off-by: Dinos Kousidis <dinos@weave.works>
* Switches context to newly created cluster by default, except if if --switch-context=false is passed. * If --artifact-directory is not passed, and ~/.kube/config file exists, the context is merged in the existing file. If ~/.kube/config doesn't exist, it creates it. * Sets SilenceUsage to true in kubeconfig root command, to avoid showing the usage message in the case of error. Relevant issue: spf13/cobra#340 * Removes printing of error in Execute() of kubeconfig command to avoid printing twice an error message. Relevant issue: spf13/cobra#304 Signed-off-by: Dinos Kousidis <dinos@weave.works>
* Switches context to newly created cluster by default, except if if --switch-context=false is passed. * If --artifact-directory is not passed, and ~/.kube/config file exists, the context is merged in the existing file. If ~/.kube/config doesn't exist, it creates it. * Sets SilenceUsage to true in kubeconfig root command, to avoid showing the usage message in the case of error. Relevant issue: spf13/cobra#340 * Removes printing of error in Execute() of kubeconfig command to avoid printing twice an error message. Relevant issue: spf13/cobra#304 Signed-off-by: Dinos Kousidis <dinos@weave.works>
* Switches context to newly created cluster by default, except if if --switch-context=false is passed. * If --artifact-directory is not passed, and ~/.kube/config file exists, the context is merged in the existing file. If ~/.kube/config doesn't exist, it creates it. * Sets SilenceUsage to true in kubeconfig root command, to avoid showing the usage message in the case of error. Relevant issue: spf13/cobra#340 * Removes printing of error in Execute() of kubeconfig command to avoid printing twice an error message. Relevant issue: spf13/cobra#304 Signed-off-by: Dinos Kousidis <dinos@weave.works>
* Switches context to newly created cluster by default, except if if --switch-context=false is passed. * If --artifact-directory is not passed, and ~/.kube/config file exists, the context is merged in the existing file. If ~/.kube/config doesn't exist, it creates it. * Sets SilenceUsage to true in kubeconfig root command, to avoid showing the usage message in the case of error. Relevant issue: spf13/cobra#340 * Removes printing of error in Execute() of kubeconfig command to avoid printing twice an error message. Relevant issue: spf13/cobra#304 Signed-off-by: Dinos Kousidis <dinos@weave.works>
* Switches context to newly created cluster by default, except if if --switch-context=false is passed. * If --artifact-directory is not passed, and ~/.kube/config file exists, the context is merged in the existing file. If ~/.kube/config doesn't exist, it creates it. * Sets SilenceUsage to true in kubeconfig root command, to avoid showing the usage message in the case of error. Relevant issue: spf13/cobra#340 * Removes printing of error in Execute() of kubeconfig command to avoid printing twice an error message. Relevant issue: spf13/cobra#304 Signed-off-by: Dinos Kousidis <dinos@weave.works>
* Switches context to newly created cluster by default, except if if --use-context=false is passed. * If --artifact-directory is not passed, and ~/.kube/config file exists, the context is merged in the existing file. If ~/.kube/config doesn't exist, it creates it. * Sets SilenceUsage to true in kubeconfig root command, to avoid showing the usage message in the case of error. Relevant issue: spf13/cobra#340 * Removes printing of error in Execute() of kubeconfig command to avoid printing twice an error message. Relevant issue: spf13/cobra#304 * Updates docs in `wksctl kubeconfig` part Signed-off-by: Dinos Kousidis <dinos@weave.works>
* Switches context to newly created cluster by default, except if if --use-context=false is passed. * If --artifact-directory is not passed, and ~/.kube/config file exists, the context is merged in the existing file. If ~/.kube/config doesn't exist, it creates it. * Sets SilenceUsage to true in kubeconfig root command, to avoid showing the usage message in the case of error. Relevant issue: spf13/cobra#340 * Removes printing of error in Execute() of kubeconfig command to avoid printing twice an error message. Relevant issue: spf13/cobra#304 * Updates docs in `wksctl kubeconfig` part Signed-off-by: Dinos Kousidis <dinos@weave.works>
* Switches context to newly created cluster by default, except if if --use-context=false is passed. * If --artifact-directory is not passed, and ~/.kube/config file exists, the context is merged in the existing file. If ~/.kube/config doesn't exist, it creates it. * Sets SilenceUsage to true in kubeconfig root command, to avoid showing the usage message in the case of error. Relevant issue: spf13/cobra#340 * Removes printing of error in Execute() of kubeconfig command to avoid printing twice an error message. Relevant issue: spf13/cobra#304 * Updates docs in `wksctl kubeconfig` part Signed-off-by: Dinos Kousidis <dinos@weave.works>
After fixing duplication of error messages on invalid flags, `helpFlagError` from `cli/cmd/help.go` had been simplified to default and thus was removed. Message about incorrect commands was removed. It was an attempt to fix a well known issue with Cobra (e.g spf13/cobra#706). Real solution might be doable, but sophisticated. For `Execute` function in `cli/cmd/root.go` also exists Cobra issue (spf13/cobra#304), so invalid flag error will be printed twice if we leave extra `log.Fatalf`. Other than that its implimentation repeats `handleCmdErr` function.
Usage and allowed flags are now printed when invalid flags are entered, and exit code in this case is 1. After fixing duplication of error messages on invalid flags, `helpFlagError` from `cli/cmd/help.go` had been simplified to default and thus was removed. For `Execute` function in `cli/cmd/root.go` also exists Cobra issue (spf13/cobra#304), so invalid flag error will be printed twice if we leave extra `log.Fatalf`. Other than that its implimentation repeats `handleCmdErr` function.
Usage and allowed flags are now printed when invalid flags are entered, and exit code in this case is 1. After fixing duplication of error messages on invalid flags, `helpFlagError` from `cli/cmd/help.go` had been simplified to default and thus was removed. For `Execute` function in `cli/cmd/root.go` also exists Cobra issue (spf13/cobra#304), so invalid flag error will be printed twice if we leave extra `log.Fatalf`. Other than that its implimentation repeats `handleCmdErr` function. Closes #274
Usage and allowed flags are now printed when invalid flags are entered, and exit code in this case is 1. After fixing duplication of error messages on invalid flags, `helpFlagError` from `cli/cmd/help.go` had been simplified to default and thus was removed. For `Execute` function in `cli/cmd/root.go` also exists Cobra issue (spf13/cobra#304), so invalid flag error will be printed twice if we leave extra `log.Fatalf`. Other than that its implimentation repeats `handleCmdErr` function. Closes #274
So I am facing a similar issue. Question is, if there is some unknown issue from the root cmd then how would I handle it if the main/execute doesn't have the print? |
According to spf13/cobra#304 (comment) cobra already prints errors reported from RunE
According to spf13/cobra#304 (comment) cobra already prints errors reported from RunE
OS: Windows 10 Pro 64bit
If there is a spelling mistake in the command, the error message is printed twice:
How to reproduce
The text was updated successfully, but these errors were encountered: