{"record":{"id":"f2e108749c78fee1","repo":"vitest-dev/vitest","slug":"benchmark-provider-did-not-return-a-result-for","errorCode":null,"errorMessage":"benchmark provider did not return a result for \"${name}\"","messagePattern":"benchmark provider did not return a result for \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/runtime/benchmark.ts","lineNumber":386,"sourceCode":"            entries,\n          ].join('\\n'),\n        )\n      }\n    }\n  }\n\n  const runSingle = async (\n    name: string,\n    fn: BenchFn,\n    fnOpts: BenchOptions | undefined,\n    options: BenchRunOptions | undefined,\n    meta: TaskMeta | undefined,\n    writeResult: string | undefined,\n  ): Promise<BenchResult> => {\n    const results = await runGroup([{ name, fn, fnOpts }], options)\n    const result = results.get(name)\n    if (!result) {\n      throw new Error(`benchmark provider did not return a result for \"${name}\"`)\n    }\n    await recordBenchmark([result], groupName(options), meta ? new Map([[name, meta]]) : undefined)\n    if (writeResult) {\n      await writeResultArtifact(writeResult, result)\n    }\n    return result\n  }\n\n  const runFrom = async (\n    name: string,\n    source: string | BenchFromSource,\n  ): Promise<BenchResult> => {\n    const data = await resolveFromSource(source)\n    const benchmark: TestBenchmark = {\n      name: test.fullTestName,\n      tasks: [{ ...taskFromBaseline(name, data), rank: 1 }],\n    }\n    test.benchmarks.push(benchmark)","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/runtime/benchmark.ts#L368-L404","documentation":"When `bench(name, fn).run()` executes, Vitest calls the resolved `BenchmarkProvider.run` and expects a `BenchResult[]` containing one entry whose `name` matches the registration. This error fires when the provider returns an array without an entry for that name. It indicates a custom provider contract violation (the built-in default provider always returns matching results).","triggerScenarios":"A custom `BenchmarkProvider.run(group)` returns results whose `.name` fields do not cover every `group.registrations[].name`. The map built at benchmark.ts:345-349 keys results by `result.name`; `runSingle` then does `results.get(name)` and throws on miss (benchmark.ts:384-386).","commonSituations":"Custom provider returns results keyed by a transformed name (e.g. slugified, suffixed); provider drops results for benchmarks that errored instead of returning a failed-result entry; provider returns an empty array; provider returns results for a different group due to a stale cache.","solutions":["Ensure the custom `BenchmarkProvider.run` returns exactly one `BenchResult` per `group.registrations` entry, with `result.name === registration.name`.","If a benchmark cannot be measured, return a result entry with the matching name and a flagged-error status rather than omitting it.","If you did not author a custom provider, this indicates a Vitest bug — file an issue with the provider name and the group registrations.","Double-check the provider is not caching results across different benchmark groups (the cache at benchmark.ts:130 caches the provider module, not results)."],"exampleFix":"// before - custom provider\nasync run(group) {\n  return group.registrations.map(r => runBench(r)).filter(Boolean) // drops failures\n}\n\n// after\nasync run(group) {\n  return group.registrations.map(r => {\n    try { return makeResult(r.name, runBench(r)) }\n    catch (e) { return makeFailedResult(r.name, e) }\n  })\n}","handlingStrategy":"validation","validationCode":"const results = await provider.run(group); const missing = group.registrations.filter(r => !results.some(res => res.name === r.name)); if (missing.length) throw new Error(`provider missing: ${missing.map(m => m.name).join(', ')}`)","typeGuard":"function coversAllNames(results: BenchResult[], names: string[]): boolean { const s = new Set(results.map(r => r.name)); return names.every(n => s.has(n)) }","tryCatchPattern":"try { return await runSingle(name, fn, fnOpts, options, meta, writeResult) } catch (e) { if (/did not return a result/.test(e.message)) { logProviderDiagnostics(provider, name); } throw e }","preventionTips":["In a custom provider, map over `group.registrations` 1:1 and always return a result per name.","Add a provider unit test asserting `results.length === registrations.length` and name coverage.","Never omit errored benchmarks — return a failed-result entry with the right name."],"tags":["benchmark","provider","api-contract","result-mismatch"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}