removed panic, and replaced with error

Signed-off-by: EItanya <eitan.yarmush@solo.io>
pull/8227/head
EItanya 6 years ago committed by Vlad Fratila
parent 1b428cd943
commit 207267a993

@ -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() {

@ -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

@ -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
}

Loading…
Cancel
Save