{"record":{"id":"d8b1f4562f5ac2f4","repo":"mastra-ai/mastra","slug":"snapshot-file-not-found-snapshotpath-run-with","errorCode":null,"errorMessage":"Snapshot file not found: ${snapshotPath}\nRun with { updateSnapshot: true } to create it.","messagePattern":"Snapshot file not found: (.+?)\nRun with (.+?) to create it\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"observability/mastra/src/exporters/test.ts","lineNumber":1294,"sourceCode":"    // Check option to update snapshot\n    const shouldUpdate = options?.updateSnapshot;\n\n    // If updating snapshot, write and return\n    if (shouldUpdate) {\n      const { writeFile } = await import('node:fs/promises');\n      await writeFile(snapshotPath, currentJson, 'utf-8');\n      this.logger.info(`TestExporter: updated snapshot ${snapshotPath}`);\n      return;\n    }\n\n    let snapshotData: { __structure__?: string[]; spans?: unknown } | unknown[];\n    let snapshotContent: string;\n    try {\n      const { readFile } = await import('node:fs/promises');\n      snapshotContent = await readFile(snapshotPath, 'utf-8');\n    } catch (err: unknown) {\n      if (err && typeof err === 'object' && 'code' in err && (err as NodeJS.ErrnoException).code === 'ENOENT') {\n        throw new Error(\n          `Snapshot file not found: ${snapshotPath}\\n` + `Run with { updateSnapshot: true } to create it.`,\n        );\n      }\n      throw err;\n    }\n    try {\n      snapshotData = JSON.parse(snapshotContent);\n    } catch (err: unknown) {\n      throw new Error(`Failed to parse snapshot ${snapshotPath}: ${err instanceof Error ? err.message : String(err)}`);\n    }\n\n    // Handle both old format (array) and new format (object with __structure__ and spans)\n    let expectedSpans: unknown;\n    let expectedStructure: string[] | undefined;\n\n    if (Array.isArray(snapshotData)) {\n      // Old format: just the spans array\n      expectedSpans = snapshotData;","sourceCodeStart":1276,"sourceCodeEnd":1312,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/observability/mastra/src/exporters/test.ts#L1276-L1312","documentation":"When updateSnapshot is falsy, TestExporter reads the existing snapshot file for comparison. If the file does not exist (fs ENOENT), it rethrows as this descriptive error rather than a raw ENOENT, instructing the developer to run with { updateSnapshot: true } to create the baseline.","triggerScenarios":"Running the TestExporter snapshot comparison where snapshotPath points to a file that was never generated, was deleted, was moved, or was excluded by .gitignore / clean scripts.","commonSituations":"Fresh clone where snapshots are gitignored; CI checkout missing snapshot fixtures; renaming a test suite without regenerating its snapshot; machine that never executed the update pass.","solutions":["Run once with { updateSnapshot: true } to create the snapshot file","Restore the missing snapshot file from version control (commit snapshots if they are intended baselines)","Verify snapshotPath/snapshotsDir points at the directory where snapshots actually live","Fix CI so snapshot fixtures are checked out, not gitignored"],"exampleFix":"// before\nconst exporter = new TestExporter(); // compares against missing snapshot\n// after\nconst exporter = new TestExporter({ updateSnapshot: true }); // first run creates baseline","handlingStrategy":"validation","validationCode":"import { existsSync } from 'node:fs';\nconst snapshotPath = resolveSnapshotPath(suite);\nif (!existsSync(snapshotPath)) {\n  throw new Error(`Snapshot missing: ${snapshotPath}. Run once with updateSnapshot: true.`);\n}","typeGuard":"function snapshotExists(p: string | undefined | null): p is string {\n  return typeof p === 'string' && p.length > 0 && existsSync(p);\n}","tryCatchPattern":"try {\n  await exporter.export(spans, callback);\n} catch (err) {\n  if ((err as Error).message.startsWith('Snapshot file not found')) {\n    await new TestExporter({ updateSnapshot: true }).export(spans, callback);\n  } else throw err;\n}","preventionTips":["Run the updateSnapshot pass after adding/renaming suites","Commit snapshot baselines or generate them in a pre-CI step","Don't gitignore snapshot directories used for comparison","Verify snapshotsDir resolves to the intended path"],"tags":["snapshots","missing-file","filesystem","ci"],"backgroundTag":"snapshot-file-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}