diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 439573426..e1ce1ad28 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -79,7 +79,12 @@ func main() { if err := cmd.Execute(); err != nil { debug("%+v", err) - os.Exit(1) + switch e := err.(type) { + case pluginError: + os.Exit(e.code) + default: + os.Exit(1) + } } } diff --git a/cmd/helm/load_plugins.go b/cmd/helm/load_plugins.go index 96c587dd3..568adb265 100644 --- a/cmd/helm/load_plugins.go +++ b/cmd/helm/load_plugins.go @@ -22,6 +22,7 @@ import ( "os/exec" "path/filepath" "strings" + "syscall" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -29,6 +30,11 @@ import ( "helm.sh/helm/pkg/plugin" ) +type pluginError struct { + error + code int +} + // loadPlugins loads plugins into the command list. // // This follows a different pattern than the other commands because it has @@ -91,7 +97,11 @@ func loadPlugins(baseCmd *cobra.Command, out io.Writer) { if err := prog.Run(); err != nil { if eerr, ok := err.(*exec.ExitError); ok { os.Stderr.Write(eerr.Stderr) - return errors.Errorf("plugin %q exited with error", md.Name) + status := eerr.Sys().(syscall.WaitStatus) + return pluginError{ + error: errors.Errorf("plugin %q exited with error", md.Name), + code: status.ExitStatus(), + } } return err }