From 5cbdac6cdf31646e60cc539c17830bd51b441bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Jane=C5=BE?= Date: Thu, 3 Sep 2020 12:35:42 +0200 Subject: [PATCH] go: Fix CLI tools to not print error messages twice Previously, Execute() called nodeCommon.EarlyLogAndExit() if there was an error running rootCmd.Execute() which in turn printed the error to stderr. The error message is printed to stdout via github.com/spf13/cobra's ExecuteC() already, so this resulted in the same error message being printed twice. This is an expansion of f5f906b3c076290d20ea6cbd298ce548c2000513 which fixed this behavior for go/oasis-test-runner/cmd. --- .changelog/3230.bugfix.md | 1 + go/extra/stats/cmd/root.go | 3 ++- go/oasis-net-runner/cmd/root.go | 2 +- go/oasis-node/cmd/root.go | 3 ++- go/oasis-remote-signer/cmd/root.go | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 .changelog/3230.bugfix.md diff --git a/.changelog/3230.bugfix.md b/.changelog/3230.bugfix.md new file mode 100644 index 00000000000..1031b45f092 --- /dev/null +++ b/.changelog/3230.bugfix.md @@ -0,0 +1 @@ +go: Fix CLI tools to not print error messages twice diff --git a/go/extra/stats/cmd/root.go b/go/extra/stats/cmd/root.go index 7b75b688be3..a05723c2e13 100644 --- a/go/extra/stats/cmd/root.go +++ b/go/extra/stats/cmd/root.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" + "os" "github.com/spf13/cobra" flag "github.com/spf13/pflag" @@ -38,7 +39,7 @@ func Execute() { } if err := rootCmd.Execute(); err != nil { - common.EarlyLogAndExit(err) + os.Exit(1) } } diff --git a/go/oasis-net-runner/cmd/root.go b/go/oasis-net-runner/cmd/root.go index 905befce330..d233b5ca0c7 100644 --- a/go/oasis-net-runner/cmd/root.go +++ b/go/oasis-net-runner/cmd/root.go @@ -57,7 +57,7 @@ func RootCmd() *cobra.Command { // Execute spawns the main entry point after handing the config file. func Execute() { if err := rootCmd.Execute(); err != nil { - common.EarlyLogAndExit(err) + os.Exit(1) } } diff --git a/go/oasis-node/cmd/root.go b/go/oasis-node/cmd/root.go index 4ec986bb9c2..9ca67207bfb 100644 --- a/go/oasis-node/cmd/root.go +++ b/go/oasis-node/cmd/root.go @@ -2,6 +2,7 @@ package cmd import ( + "os" "syscall" "github.com/spf13/cobra" @@ -41,7 +42,7 @@ func Execute() { syscall.Umask(0o077) if err := rootCmd.Execute(); err != nil { - cmdCommon.EarlyLogAndExit(err) + os.Exit(1) } } diff --git a/go/oasis-remote-signer/cmd/root.go b/go/oasis-remote-signer/cmd/root.go index 9ac4fa3a4b8..e3ebbb963ac 100644 --- a/go/oasis-remote-signer/cmd/root.go +++ b/go/oasis-remote-signer/cmd/root.go @@ -62,7 +62,7 @@ var ( // Execute spawns the main entry point after handling the config file. func Execute() { if err := rootCmd.Execute(); err != nil { - cmdCommon.EarlyLogAndExit(err) + os.Exit(1) } }