Skip to content

Commit cda5dbe

Browse files
committed
fix: Fix potential regression issue with failed command outputs
Fix the handling of grouped outputs where a child task failing may result in the output of the commands of a parent task when that parent task itself didn't fail. Therefore when running with error_only output, task should not accidentally output more than a single task's output.
1 parent 49e9ee6 commit cda5dbe

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

task.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,13 @@ func (e *Executor) runCommand(ctx context.Context, t *ast.Task, call *Call, i in
452452
if err != nil && timedOut(ctx, timeout) {
453453
err = timeout
454454
}
455-
if taskOut != nil && err != nil {
456-
taskOut.failed = true
457-
}
458455
if cmd.IgnoreError && isCommandFailure(err) {
459456
e.Logger.VerboseErrf(logger.Yellow, "task: [%s] task error ignored: %v\n", t.Name(), err)
460457
return nil
461458
}
459+
if taskOut != nil && err != nil {
460+
taskOut.failed = true
461+
}
462462
return err
463463
case cmd.Cmd != "":
464464
if !shouldRunOnCurrentPlatform(cmd.Platforms) {
@@ -506,8 +506,6 @@ func (e *Executor) runCommand(ctx context.Context, t *ast.Task, call *Call, i in
506506
if closeErr := closer(err); closeErr != nil {
507507
e.Logger.Errf(logger.Red, "task: unable to close writer: %v\n", closeErr)
508508
}
509-
} else if err != nil {
510-
taskOut.failed = true
511509
}
512510
if err != nil && timedOut(ctx, timeout) {
513511
err = timeout
@@ -516,6 +514,9 @@ func (e *Executor) runCommand(ctx context.Context, t *ast.Task, call *Call, i in
516514
e.Logger.VerboseErrf(logger.Yellow, "task: [%s] command error ignored: %v\n", t.Name(), err)
517515
return nil
518516
}
517+
if taskOut != nil && err != nil {
518+
taskOut.failed = true
519+
}
519520
return err
520521
default:
521522
return nil

task_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,14 @@ func TestOutputGroupByTaskErrorOnly(t *testing.T) {
27182718
buff.Reset()
27192719
require.Error(t, e.Run(t.Context(), &task.Call{Task: "failing"}))
27202720
assert.Equal(t, "failing-first\nfailing-second\n", buff.String())
2721+
2722+
buff.Reset()
2723+
require.NoError(t, e.Run(t.Context(), &task.Call{Task: "ignored-command"}))
2724+
assert.Empty(t, buff.String())
2725+
2726+
buff.Reset()
2727+
require.NoError(t, e.Run(t.Context(), &task.Call{Task: "ignored-task"}))
2728+
assert.Equal(t, "child-failing-first\nchild-failing-second\n", buff.String())
27212729
}
27222730

27232731
func TestOutputGroupErrorOnlySwallowsOutputOnSuccess(t *testing.T) {

testdata/output_group_by_task_error_only/Taskfile.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,21 @@ tasks:
1717
cmds:
1818
- echo 'failing-first'
1919
- echo 'failing-second' && exit 1
20+
21+
ignored-command:
22+
cmds:
23+
- echo 'ignored-command-first'
24+
- cmd: echo 'ignored-command-failure' && exit 1
25+
ignore_error: true
26+
- echo 'ignored-command-last'
27+
28+
child-failing:
29+
cmds:
30+
- echo 'child-failing-first'
31+
- echo 'child-failing-second' && exit 1
32+
33+
ignored-task:
34+
cmds:
35+
- task: child-failing
36+
ignore_error: true
37+
- echo 'ignored-task-parent'

0 commit comments

Comments
 (0)