mirror of
https://github.com/go-task/task.git
synced 2025-01-20 04:59:37 +02:00
Allow ignore_error at task level
This commit is contained in:
parent
c70343a5bc
commit
feaf70922d
@ -18,4 +18,5 @@ type Task struct {
|
||||
Silent bool
|
||||
Method string
|
||||
Prefix string
|
||||
IgnoreError bool `yaml:"ignore_error"`
|
||||
}
|
||||
|
6
task.go
6
task.go
@ -182,6 +182,12 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {
|
||||
if err2 := statusOnError(t); err2 != nil {
|
||||
e.Logger.VerboseErrf("task: error cleaning status on error: %v", err2)
|
||||
}
|
||||
|
||||
if _, ok := err.(interp.ExitCode); ok && t.IgnoreError {
|
||||
e.Logger.VerboseErrf("task: task error ignored: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
return &taskRunError{t.Task, err}
|
||||
}
|
||||
}
|
||||
|
20
task_test.go
20
task_test.go
@ -416,6 +416,26 @@ func TestTaskVersion(t *testing.T) {
|
||||
func TestTaskIgnoreErrors(t *testing.T) {
|
||||
const dir = "testdata/ignore_errors"
|
||||
|
||||
t.Run("task-should-pass", func(t *testing.T) {
|
||||
e := task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: ioutil.Discard,
|
||||
Stderr: ioutil.Discard,
|
||||
}
|
||||
assert.NoError(t, e.Setup())
|
||||
assert.NoError(t, e.Run(taskfile.Call{Task: "task-should-pass"}))
|
||||
})
|
||||
|
||||
t.Run("task-should-fail", func(t *testing.T) {
|
||||
e := task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: ioutil.Discard,
|
||||
Stderr: ioutil.Discard,
|
||||
}
|
||||
assert.NoError(t, e.Setup())
|
||||
assert.Error(t, e.Run(taskfile.Call{Task: "task-should-fail"}))
|
||||
})
|
||||
|
||||
t.Run("cmd-should-pass", func(t *testing.T) {
|
||||
e := task.Executor{
|
||||
Dir: dir,
|
||||
|
11
testdata/ignore_errors/Taskfile.yml
vendored
11
testdata/ignore_errors/Taskfile.yml
vendored
@ -1,6 +1,15 @@
|
||||
version: 2
|
||||
version: '2'
|
||||
|
||||
tasks:
|
||||
task-should-pass:
|
||||
cmds:
|
||||
- exit 1
|
||||
ignore_error: true
|
||||
|
||||
task-should-fail:
|
||||
cmds:
|
||||
- exit 1
|
||||
|
||||
cmd-should-pass:
|
||||
cmds:
|
||||
- cmd: exit 1
|
||||
|
@ -35,6 +35,7 @@ func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) {
|
||||
Silent: origTask.Silent,
|
||||
Method: r.Replace(origTask.Method),
|
||||
Prefix: r.Replace(origTask.Prefix),
|
||||
IgnoreError: origTask.IgnoreError,
|
||||
}
|
||||
new.Dir, err = shell.Expand(new.Dir, nil)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user