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() initKubeLogs()
actionConfig := new(action.Configuration) 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 // run when each command's execute method is called
cobra.OnInitialize(func() { cobra.OnInitialize(func() {

@ -115,9 +115,12 @@ func executeActionCommandStdinC(store *storage.Storage, in *os.File, cmd string)
Log: func(format string, v ...interface{}) {}, Log: func(format string, v ...interface{}) {},
} }
root := newRootCmd(actionConfig, buf, args) root, err := newRootCmd(actionConfig, buf, args)
root.SetOut(buf) if err != nil {
root.SetErr(buf) return nil, "", err
}
root.SetOutput(buf)
root.SetArgs(args) root.SetArgs(args)
oldStdin := os.Stdin 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 | | 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{ cmd := &cobra.Command{
Use: "helm", Use: "helm",
Short: "The Helm package manager for Kubernetes.", 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), registry.ClientOptCredentialsFile(settings.RegistryConfig),
) )
if err != nil { if err != nil {
// TODO: don't panic here, refactor newRootCmd to return error return nil, err
panic(err)
} }
actionConfig.RegistryClient = registryClient actionConfig.RegistryClient = registryClient
cmd.AddCommand( cmd.AddCommand(
@ -188,5 +187,5 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string
// Find and add plugins // Find and add plugins
loadPlugins(cmd, out) loadPlugins(cmd, out)
return cmd return cmd, nil
} }

Loading…
Cancel
Save