From 337ed48fb26f3bf6cd7b1aa7d8043bac7394b057 Mon Sep 17 00:00:00 2001 From: yxxhero Date: Sat, 19 Sep 2020 11:23:36 +0800 Subject: [PATCH] Unified error handling when calling newRootCmd. Signed-off-by: yxxhero --- cmd/helm/helm.go | 3 +-- cmd/helm/root.go | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 98cb00f43..ab5120c8d 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -75,8 +75,7 @@ func main() { actionConfig := new(action.Configuration) cmd, err := newRootCmd(actionConfig, os.Stdout, os.Args[1:]) if err != nil { - debug("%+v", err) - os.Exit(1) + log.Fatal(err) } // run when each command's execute method is called diff --git a/cmd/helm/root.go b/cmd/helm/root.go index 91542bb7e..08115bf2e 100644 --- a/cmd/helm/root.go +++ b/cmd/helm/root.go @@ -20,7 +20,6 @@ import ( "context" "fmt" "io" - "log" "strings" "github.com/spf13/cobra" @@ -116,7 +115,7 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string }) if err != nil { - log.Fatal(err) + return nil, err } // Setup shell completion for the kube-context flag @@ -142,7 +141,7 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string }) if err != nil { - log.Fatal(err) + return nil, err } // We can safely ignore any errors that flags.Parse encounters since