{"id":"e78d4340863a7804","repo":"vitest-dev/vitest","slug":"task-name-was-not-defined","errorCode":null,"errorMessage":"task \"${name}\" was not defined","messagePattern":"task \"(.+?)\" was not defined","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/runtime/benchmark.ts","lineNumber":274,"sourceCode":"    period: data.period,\n    totalTime: data.totalTime,\n    rank: 0,\n    fromStore: true,\n  })\n\n  const createCompareStorage = <T extends string>(\n    results: Map<string, BenchResult>,\n    fromResults?: Map<string, BaselineData>,\n  ): BenchStorage<T> => {\n    return {\n      get(name: T) {\n        const stored = fromResults?.get(name)\n        if (stored) {\n          return stored as BenchResult\n        }\n        const result = results.get(name)\n        if (!result) {\n          throw new Error(`task \"${name}\" was not defined`)\n        }\n        return result\n      },\n    }\n  }\n\n  interface TaskMeta { perProject?: true }\n\n  const serializeBenchmark = (\n    results: BenchResult[],\n    name: string,\n    taskMeta?: Map<string, TaskMeta>,\n    fromTasks?: TestBenchmarkTask[],\n  ): TestBenchmark => {\n    const tasks: TestBenchmarkTask[] = results.map(result => ({\n      name: result.name,\n      latency: result.latency,\n      throughput: result.throughput,","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/runtime/benchmark.ts#L256-L292","documentation":"Thrown by the storage `get(name)` returned from `bench.compare(...)` (benchmark.ts:274) when you request a result by name that was not one of the registrations passed to `bench.compare()`. After a compare run, Vitest builds a result map keyed by registration name; looking up an undefined name means the task was never registered in that compare group.","triggerScenarios":"Calling `storage.get('three')` when `bench.compare(oneReg, twoReg)` only registered `one` and `two`; a typo in the name; passing a different name string than the one used at registration.","commonSituations":"Refactoring benchmark names and forgetting to update lookups; copy-paste errors in the storage access; referencing a baseline name that wasn't included in the compare call.","solutions":["Only call `storage.get(name)` with names that were registered in the same `bench.compare(...)` call.","Double-check the spelling/casing of the name against the registration.","Register the missing benchmark in the compare group if it should be part of the comparison."],"exampleFix":"// before\nconst store = await bench.compare(\n  bench('one', fn1),\n  bench('two', fn2),\n)\nstore.get('three') // throws\n\n// after\nstore.get('one')","handlingStrategy":"validation","validationCode":"const validNames = new Set(registrations.map(r => r.name))\nif (!validNames.has(requestedName)) throw new Error(`\"${requestedName}\" was not registered in bench.compare()`)","typeGuard":"const isRegisteredName = (names: readonly string[], n: string): n is (typeof names)[number] =>\n  (names as readonly string[]).includes(n)","tryCatchPattern":null,"preventionTips":["Capture registration names in a `const` tuple and look up only those literals.","Avoid constructing names dynamically for storage lookups.","Keep name strings identical between `bench(...)` and `storage.get(...)`."],"tags":["benchmark","bench-compare","validation","api-usage"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}