Skip to content

fix: Task failure errors include stack of running tasks. #2286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions errors/errors_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func (err *TaskRunError) TaskExitCode() int {
return err.Code()
}

func (err *TaskRunError) Unwrap() error {
return err.Err
}

// TaskInternalError when the user attempts to invoke a task that is internal.
type TaskInternalError struct {
TaskName string
Expand Down
9 changes: 9 additions & 0 deletions executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,15 @@ func TestLabel(t *testing.T) {
),
WithTask("foo"),
)

NewExecutorTest(t,
WithName("label in error"),
WithExecutorOptions(
task.WithDir("testdata/label_error"),
),
WithTask("foo"),
WithRunError(),
)
}

func TestPromptInSummary(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (e *Executor) RunTask(ctx context.Context, call *Call) error {
release := e.acquireConcurrencyLimit()
defer release()

return e.startExecution(ctx, t, func(ctx context.Context) error {
if err = e.startExecution(ctx, t, func(ctx context.Context) error {
e.Logger.VerboseErrf(logger.Magenta, "task: %q started\n", call.Task)
if err := e.runDeps(ctx, t); err != nil {
return err
Expand Down Expand Up @@ -229,16 +229,16 @@ func (e *Executor) RunTask(ctx context.Context, call *Call) error {
deferredExitCode = exitCode
}

if call.Indirect {
return err
}

return &errors.TaskRunError{TaskName: t.Task, Err: err}
return err
}
}
e.Logger.VerboseErrf(logger.Magenta, "task: %q finished\n", call.Task)
return nil
})
}); err != nil {
return &errors.TaskRunError{TaskName: t.Name(), Err: err}
}

return nil
}

func (e *Executor) mkdir(t *ast.Task) error {
Expand Down
4 changes: 3 additions & 1 deletion task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ func TestCyclicDep(t *testing.T) {
task.WithStderr(io.Discard),
)
require.NoError(t, e.Setup())
assert.IsType(t, &errors.TaskCalledTooManyTimesError{}, e.Run(context.Background(), &task.Call{Task: "task-1"}))
err := e.Run(context.Background(), &task.Call{Task: "task-1"})
var taskCalledTooManyTimesError *errors.TaskCalledTooManyTimesError
assert.ErrorAs(t, err, &taskCalledTooManyTimesError)
}

func TestTaskVersion(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions testdata/label_error/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3'

tasks:
foo:
label: "foobar"
cmds:
- "false"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
task: Failed to run task "foobar": exit status 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
task: [foobar] false
Original file line number Diff line number Diff line change
@@ -1 +1 @@
task: precondition not met
task: Failed to run task "impossible": task: precondition not met
Original file line number Diff line number Diff line change
@@ -1 +1 @@
task: Failed to run task "executes_failing_task_as_cmd": task: precondition not met
task: Failed to run task "executes_failing_task_as_cmd": task: Failed to run task "impossible": task: precondition not met
Original file line number Diff line number Diff line change
@@ -1 +1 @@
task: precondition not met
task: Failed to run task "depends_on_impossible": task: Failed to run task "impossible": task: precondition not met
Original file line number Diff line number Diff line change
@@ -1 +1 @@
task: Task "foo" cancelled by user
task: Failed to run task "foo": task: Task "foo" cancelled by user
Original file line number Diff line number Diff line change
@@ -1 +1 @@
task: Task "foo" cancelled by user
task: Failed to run task "foo": task: Task "foo" cancelled by user
Original file line number Diff line number Diff line change
@@ -1 +1 @@
task: Task "foo" cancelled by user
task: Failed to run task "foo": task: Task "foo" cancelled by user
Original file line number Diff line number Diff line change
@@ -1 +1 @@
task: Task "foo" cancelled by user
task: Failed to run task "foo": task: Task "foo" cancelled by user
Loading