mirror of
https://github.com/helm/helm.git
synced 2026-08-08 17:11:18 +00:00
fix(helm3): Detailed exit code for helm plugins
Fixes #6384 Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
committed by
Yusuke Kuoka
parent
bc42dca470
commit
6e9211e7bb
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user