Skip to content

fix: report cancellation reason when parallel tasks fail in failfast mode#2870

Closed
toller892 wants to merge 1 commit into
go-task:mainfrom
toller892:fix/report-cancellation-reason-for-parallel-tasks
Closed

fix: report cancellation reason when parallel tasks fail in failfast mode#2870
toller892 wants to merge 1 commit into
go-task:mainfrom
toller892:fix/report-cancellation-reason-for-parallel-tasks

Conversation

@toller892
Copy link
Copy Markdown

@toller892 toller892 commented Jun 1, 2026

Problem

When failfast is enabled and multiple tasks run in parallel, if one task fails, the other running tasks are cancelled via context. However, the error message only shows context cancelled without explaining why the task was cancelled. This makes it hard for users to understand what happened.

Current behavior:

⯈lint:mypy
⯈CI:test
task: Failed to run task "CI:test": context canceled
task: Failed to run task "CI:lint": exit status 1

The user sees context canceled for CI:test but has no idea it was cancelled because CI:lint failed.

Solution

Use context.Cause() to extract the original error that triggered the cancellation and include it in the error message. The errgroup.WithContext function (used when failfast is enabled) stores the first error as the context cause via context.WithCancelCause.

New behavior:

⯈lint:mypy
⯈CI:test
task: Failed to run task "CI:test": task: cancelled due to: exit status 1
task: Failed to run task "CI:lint": exit status 1

Changes

  • task.go: Added enrichCancellationError helper that checks for context.Canceled errors and enriches them with the cause from context.Cause(ctx)
  • Applied to both Run() (top-level parallel tasks) and runDeps() (dependency tasks)

Testing

  • All existing tests pass, including TestFailfast
  • The change is minimal and only affects error messages, not behavior

Fixes #1226

…mode

When failfast is enabled and a parallel task fails, other running tasks
are cancelled via context but the error message only shows 'context
cancelled' without explaining why. Use context.Cause() to extract the
original error and include it in the cancellation message.

Fixes go-task#1226
@trulede
Copy link
Copy Markdown
Contributor

trulede commented Jun 1, 2026

AI Bot.

@trulede trulede closed this Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Report reason for cancellation of parallel task

2 participants