{"id":"979df4d19d874923","repo":"vitest-dev/vitest","slug":"task-task-name-did-not-complete-received","errorCode":null,"errorMessage":"task \"${task.name}\" did not complete: received \"${result.state}\"","messagePattern":"task \"(.+?)\" did not complete: received \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/runtime/benchmark/default-provider.ts","lineNumber":49,"sourceCode":"      const errors = tinybench.tasks\n        .filter(task => task.result.state === 'errored')\n        .map(task => (task.result as { error: unknown }).error)\n      if (errors.length === 1) {\n        throw errors[0]\n      }\n      if (errors.length > 1) {\n        throw new AggregateError(errors, 'Some benchmarks failed')\n      }\n\n      return tinybench.tasks.map(toBenchResult)\n    },\n  }\n}\n\nfunction toBenchResult(task: TinybenchTask): BenchResult {\n  const result = task.result\n  if (result.state !== 'completed') {\n    throw new Error(`task \"${task.name}\" did not complete: received \"${result.state}\"`)\n  }\n  return {\n    ...result,\n    name: task.name,\n  }\n}\n","sourceCodeStart":31,"sourceCodeEnd":56,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/runtime/benchmark/default-provider.ts#L31-L56","documentation":"`toBenchResult` (`default-provider.ts:49`) converts a tinybench task into a `BenchResult`, but only completed tasks are serializable. It throws when `task.result.state !== 'completed'` — e.g. `'cancelled'` or `'failed'` states that slipped past the error-aggregation step. This is a defensive guard ensuring the reporter never sees half-finished statistics.","triggerScenarios":"A benchmark aborted via the test context's `AbortSignal` (state becomes cancelled); a custom provider returning tasks in a non-completed state; tinybench returning an unexpected state.","commonSituations":"Test timeout aborting the benchmark run; manual cancellation; a misbehaving custom BenchmarkProvider.","solutions":["Ensure benchmarks aren't aborted mid-run — check for test timeouts shorter than benchmark duration.","If using a custom provider, only return tasks whose `result.state === 'completed'`.","Increase the test timeout or reduce benchmark iterations so the run finishes."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Ensure the benchmark can finish: timeouts must exceed expected runtime.\n// Pass a generous timeout and don't abort the signal mid-run.\ntest('bench', async ({ bench }) => {\n  bench('x', () => work())\n}, 60_000 /* generous timeout */)","typeGuard":null,"tryCatchPattern":"try {\n  await reg.run()\n} catch (e) {\n  if (e instanceof Error && /did not complete/.test(e.message)) {\n    // increase timeout / reduce iterations / avoid aborting the signal\n  }\n  throw e\n}","preventionTips":["Set test timeouts generously relative to benchmark duration.","Don't abort the test context signal while benchmarks are running.","If using a custom BenchmarkProvider, only return tasks with state 'completed'."],"tags":["benchmark","runtime","defensive","abort","tinybench"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}