mirror of
https://github.com/helm/helm.git
synced 2026-04-22 23:00:01 -04:00
Merge pull request #6385 from mumoshu/detailed-plugin-exit-code-v3
fix(helm3): Detailed exit code for helm plugins
This commit is contained in:
commit
d285097f58
2 changed files with 17 additions and 2 deletions
|
|
@ -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…
Reference in a new issue