Merge pull request #6385 from mumoshu/detailed-plugin-exit-code-v3

fix(helm3): Detailed exit code for helm plugins
pull/6387/head
Matthew Fisher 5 years ago committed by GitHub
commit d285097f58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

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

Loading…
Cancel
Save