diff --git a/internal/execext/exec.go b/internal/execext/exec.go index 4428bd39..f86003bb 100644 --- a/internal/execext/exec.go +++ b/internal/execext/exec.go @@ -13,14 +13,13 @@ import ( // RunCommandOptions is the options for the RunCommand func type RunCommandOptions struct { - Context context.Context - Command string - Dir string - Env []string - Stdin io.Reader - Stdout io.Writer - Stderr io.Writer - IgnoreErrorCode bool + Context context.Context + Command string + Dir string + Env []string + Stdin io.Reader + Stdout io.Writer + Stderr io.Writer } var ( @@ -63,12 +62,5 @@ func RunCommand(opts *RunCommandOptions) error { if err = r.Reset(); err != nil { return err } - if err = r.Run(p); err != nil { - if opts.IgnoreErrorCode { - if _, ok := err.(interp.ExitCode); ok { - return nil - } - } - } - return err + return r.Run(p) } diff --git a/task.go b/task.go index ab62c691..48f98048 100644 --- a/task.go +++ b/task.go @@ -19,6 +19,7 @@ import ( "github.com/Masterminds/semver" "golang.org/x/sync/errgroup" + "mvdan.cc/sh/interp" ) const ( @@ -221,16 +222,20 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi defer stdOut.Close() defer stdErr.Close() - return execext.RunCommand(&execext.RunCommandOptions{ - Context: ctx, - Command: cmd.Cmd, - Dir: t.Dir, - Env: getEnviron(t), - Stdin: e.Stdin, - Stdout: stdOut, - Stderr: stdErr, - IgnoreErrorCode: cmd.IgnoreError, + err := execext.RunCommand(&execext.RunCommandOptions{ + Context: ctx, + Command: cmd.Cmd, + Dir: t.Dir, + Env: getEnviron(t), + Stdin: e.Stdin, + Stdout: stdOut, + Stderr: stdErr, }) + if _, ok := err.(interp.ExitCode); ok && cmd.IgnoreError { + e.Logger.VerboseErrf("task: command error ignored: %v", err) + return nil + } + return err default: return nil }