From 23be9af2db0710bf270e8ec1046e1b03bfa8664a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9B=B8=E8=BD=A9?= <9570112+nauxliu@users.noreply.github.com> Date: Sat, 9 May 2020 12:35:31 +0800 Subject: [PATCH] Show executed command when errors occurred (#1252) --- pkg/helmexec/exit_error.go | 3 +-- pkg/helmexec/runner.go | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/helmexec/exit_error.go b/pkg/helmexec/exit_error.go index 6b11638e..9419cf42 100644 --- a/pkg/helmexec/exit_error.go +++ b/pkg/helmexec/exit_error.go @@ -2,13 +2,12 @@ package helmexec import ( "fmt" - "path/filepath" "strings" ) func newExitError(helmCmdPath string, exitStatus int, errorMessage string) ExitError { return ExitError{ - Message: fmt.Sprintf("%s exited with status %d:\n%s", filepath.Base(helmCmdPath), exitStatus, indent(strings.TrimSpace(errorMessage))), + Message: fmt.Sprintf("the following cmd exited with status %d:\n%s\n\n%s", exitStatus, indent(strings.TrimSpace(helmCmdPath)), indent(strings.TrimSpace(errorMessage))), Code: exitStatus, } } diff --git a/pkg/helmexec/runner.go b/pkg/helmexec/runner.go index 2892afc3..179c0198 100644 --- a/pkg/helmexec/runner.go +++ b/pkg/helmexec/runner.go @@ -64,7 +64,8 @@ func combinedOutput(c *exec.Cmd, logger *zap.SugaredLogger) ([]byte, error) { // so that helmfile could return its own exit code accordingly waitStatus := ee.Sys().(syscall.WaitStatus) exitStatus := waitStatus.ExitStatus() - err = newExitError(c.Path, exitStatus, string(e)) + cmd := fmt.Sprintf("%s %s", c.Path, strings.Join(c.Args, " ")) + err = newExitError(cmd, exitStatus, string(e)) default: panic(fmt.Sprintf("unexpected error: %v", err)) }