Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ func AsType[T error](err error) (T, bool) {
func Unwrap(err error) error {
return errors.Unwrap(err)
}

// Join wraps the standard errors.Join function so that we don't need to alias that package.
func Join(errs ...error) error {
return errors.Join(errs...)
}
22 changes: 18 additions & 4 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,20 @@ func (e *Executor) mkdir(t *ast.Task) error {
}

func (e *Executor) runDeps(ctx context.Context, t *ast.Task) error {
failfast := e.Failfast || t.Failfast
g := &errgroup.Group{}
if e.Failfast || t.Failfast {
if failfast {
g, ctx = errgroup.WithContext(ctx)
}

reacquire := e.releaseConcurrencyLimit()
defer reacquire()

for _, d := range t.Deps {
// Without failfast every dep runs to completion, but errgroup.Wait only
// surfaces the first error, so all dep failures are collected and joined.
// Each dep writes its own slot, keeping the message in declaration order.
errs := make([]error, len(t.Deps))
for i, d := range t.Deps {
g.Go(func() error {
depCtx := ctx
var timeout *errors.TaskTimeoutError
Expand All @@ -330,13 +335,22 @@ func (e *Executor) runDeps(ctx context.Context, t *ast.Task) error {

err := e.RunTask(depCtx, &Call{Task: d.Task, Vars: d.Vars, Silent: d.Silent, Indirect: true})
if err != nil && timedOut(depCtx, timeout) {
return timeout
err = timeout
}
if !failfast && err != nil {
errs[i] = err
}
Comment on lines +340 to 342

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !failfast && err != nil {
mu.Lock()
errs = append(errs, err)
mu.Unlock()
}
errs[i] = err

return err
})
}

return g.Wait()
if err := g.Wait(); err != nil {
if failfast {
return err
}
return errors.Join(errs...)
}
return nil
}

func (e *Executor) runDeferred(t *ast.Task, call *Call, i int, vars *ast.Vars, deferredExitCode *uint8) {
Expand Down
23 changes: 23 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,29 @@ func TestCyclicDep(t *testing.T) {
assert.ErrorAs(t, err, &taskCalledTooManyTimesError)
}

func TestParallelDepsReportAllFailures(t *testing.T) {
t.Parallel()

const dir = "testdata/deps_fail"

e := task.NewExecutor(
task.WithDir(dir),
task.WithStdout(io.Discard),
task.WithStderr(io.Discard),
)
require.NoError(t, e.Setup())
err := e.Run(t.Context(), &task.Call{Task: "default"})
require.Error(t, err)
// Both failing deps must be surfaced, not just the first one, and in the
// order they are declared.
assert.Equal(t,
"task: Failed to run task \"default\": "+
"task: Failed to run task \"fail-1\": exit status 1\n"+
"task: Failed to run task \"fail-2\": exit status 1",
err.Error(),
)
}

func TestTaskVersion(t *testing.T) {
t.Parallel()

Expand Down
15 changes: 15 additions & 0 deletions testdata/deps_fail/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'

tasks:
default:
deps: [fail-1, fail-2]
cmds:
- echo 'default'

fail-1:
cmds:
- exit 1

fail-2:
cmds:
- exit 1