From 207267a9936c61525531d639eaf2704d33e79c9a Mon Sep 17 00:00:00 2001 From: EItanya Date: Wed, 8 Jan 2020 14:03:06 -0500 Subject: [PATCH] removed panic, and replaced with error Signed-off-by: EItanya --- cmd/helm/helm.go | 5 ++++- cmd/helm/helm_test.go | 9 ++++++--- cmd/helm/root.go | 7 +++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index a21b7a238..a379f1499 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -68,7 +68,10 @@ func main() { initKubeLogs() actionConfig := new(action.Configuration) - cmd := newRootCmd(actionConfig, os.Stdout, os.Args[1:]) + cmd, err := newRootCmd(actionConfig, os.Stdout, os.Args[1:]) + if err != nil { + log.Fatal(err) + } // run when each command's execute method is called cobra.OnInitialize(func() { diff --git a/cmd/helm/helm_test.go b/cmd/helm/helm_test.go index 9ba9d78fb..15bbbe045 100644 --- a/cmd/helm/helm_test.go +++ b/cmd/helm/helm_test.go @@ -115,9 +115,12 @@ func executeActionCommandStdinC(store *storage.Storage, in *os.File, cmd string) Log: func(format string, v ...interface{}) {}, } - root := newRootCmd(actionConfig, buf, args) - root.SetOut(buf) - root.SetErr(buf) + root, err := newRootCmd(actionConfig, buf, args) + if err != nil { + return nil, "", err + } + + root.SetOutput(buf) root.SetArgs(args) oldStdin := os.Stdin diff --git a/cmd/helm/root.go b/cmd/helm/root.go index af25a0b38..fe917c75f 100644 --- a/cmd/helm/root.go +++ b/cmd/helm/root.go @@ -68,7 +68,7 @@ By default, the default directories depend on the Operating System. The defaults | Windows | %TEMP%\helm | %APPDATA%\helm | %APPDATA%\helm | ` -func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string) *cobra.Command { +func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string) (*cobra.Command, error) { cmd := &cobra.Command{ Use: "helm", Short: "The Helm package manager for Kubernetes.", @@ -176,8 +176,7 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string registry.ClientOptCredentialsFile(settings.RegistryConfig), ) if err != nil { - // TODO: don't panic here, refactor newRootCmd to return error - panic(err) + return nil, err } actionConfig.RegistryClient = registryClient cmd.AddCommand( @@ -188,5 +187,5 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string // Find and add plugins loadPlugins(cmd, out) - return cmd + return cmd, nil }