{"id":"56a67719177d166c","repo":"vitest-dev/vitest","slug":"bench-from-could-not-find-a-result-file-at","errorCode":null,"errorMessage":"`bench.from()` could not find a result file at \"${resolved}\". Run the source benchmark first to create it.","messagePattern":"`bench\\.from\\(\\)` could not find a result file at \"(.+?)\"\\. Run the source benchmark first to create it\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/runtime/benchmark.ts","lineNumber":244,"sourceCode":"}\n\nexport function createBench(\n  test: Test,\n  config: SerializedConfig,\n  moduleRunner: TestModuleRunner,\n): Bench {\n  const pending = new Set<BenchRegistration<any>>()\n\n  const resolveTemplate = (template: string) => substitutePath(template, config.benchmark.projectName)\n\n  const resolveFromSource = async (source: string | BenchFromSource): Promise<BaselineData> => {\n    if (typeof source === 'function') {\n      return source()\n    }\n    const resolved = resolveTemplate(source)\n    const data = await rpc().readBenchmarkResult(resolved)\n    if (data == null) {\n      throw new Error(`\\`bench.from()\\` could not find a result file at \"${resolved}\". Run the source benchmark first to create it.`)\n    }\n    return data\n  }\n\n  const taskFromBaseline = (\n    name: string,\n    data: BaselineData,\n  ): TestBenchmarkTask => ({\n    name,\n    latency: data.latency,\n    throughput: data.throughput,\n    period: data.period,\n    totalTime: data.totalTime,\n    rank: 0,\n    fromStore: true,\n  })\n\n  const createCompareStorage = <T extends string>(","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/runtime/benchmark.ts#L226-L262","documentation":"Thrown by `resolveFromSource` (benchmark.ts:244) when `bench.from(name, source)` is given a string path but `rpc().readBenchmarkResult(resolved)` returns null, i.e. no result file exists at that resolved path. `bench.from()` loads a previously written baseline to compare against; the source benchmark must have run first (with `writeResult`) to create the file.","triggerScenarios":"Calling `bench.from('baseline', './results/sort.json')` before any benchmark wrote `./results/sort.json`; the `writeResult` path of the source benchmark differs from the `bench.from()` path; the result file was deleted or never written because the source run failed.","commonSituations":"Running the comparison/baseline test without first running the source benchmark that writes the result; path template mismatch (e.g. `${projectName}` substitution differing between write and read); different working directories between writes and reads.","solutions":["Run the source benchmark (the one with `writeResult`) first so the baseline file is created.","Ensure the path passed to `bench.from()` matches the `writeResult` path of the source benchmark (including `${projectName}` substitution).","Verify the file exists at the resolved path before running the comparison test."],"exampleFix":"// before\nbench.from('baseline', './results/sort.json')  // file missing\n// source benchmark must write it first:\nbench('sort', { writeResult: './results/sort.json' }, () => { /* ... */ })\n\n// run the source, then the comparison","handlingStrategy":"validation","validationCode":"import { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nconst resolved = resolve(source)\nif (!existsSync(resolved)) throw new Error(`bench.from() baseline missing: ${resolved}; run the source benchmark first`)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run the source benchmark (with `writeResult`) before any test that uses `bench.from()`.","Keep `writeResult` and `bench.from()` paths identical, including `${projectName}` substitution.","Check the baseline file exists in a pre-test step."],"tags":["benchmark","bench-from","baseline","filesystem"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}