From 640d527190376a8b4945575f767065ebd47a83cb 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 | 6 +++++- cmd/helm/root.go | 7 +++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 112d5123f..952719623 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -65,7 +65,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) + } if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), os.Getenv("HELM_DRIVER"), debug); err != nil { log.Fatal(err) diff --git a/cmd/helm/helm_test.go b/cmd/helm/helm_test.go index 924e8e9d3..20e7ed3e9 100644 --- a/cmd/helm/helm_test.go +++ b/cmd/helm/helm_test.go @@ -107,7 +107,11 @@ func executeActionCommandC(store *storage.Storage, cmd string) (*cobra.Command, Log: func(format string, v ...interface{}) {}, } - root := newRootCmd(actionConfig, buf, args) + root, err := newRootCmd(actionConfig, buf, args) + if err != nil { + return nil, "", err + } + root.SetOutput(buf) root.SetArgs(args) diff --git a/cmd/helm/root.go b/cmd/helm/root.go index 1cee11458..45fbe544d 100644 --- a/cmd/helm/root.go +++ b/cmd/helm/root.go @@ -345,7 +345,7 @@ By default, the default directories depend on the Operating System. The defaults +------------------+---------------------------+--------------------------------+-------------------------+ ` -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.", @@ -419,8 +419,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( @@ -431,5 +430,5 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string // Find and add plugins loadPlugins(cmd, out) - return cmd + return cmd, nil }