{"record":{"id":"b6f3d9a8a81485ac","repo":"microsoft/playwright","slug":"trace-file-not-found-filepath","errorCode":null,"errorMessage":"Trace file not found: ${filePath}","messagePattern":"Trace file not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/tools/trace/traceUtils.ts","lineNumber":69,"sourceCode":"    return this.model.actions.find(a => a.callId === actionId);\n  }\n}\n\nfunction ensureTraceOpen(): string {\n  if (!fs.existsSync(traceDir))\n    throw new Error(`No trace opened. Run 'npx playwright trace open <file>' first.`);\n  return traceDir;\n}\n\nexport async function closeTrace() {\n  if (fs.existsSync(traceDir))\n    await fs.promises.rm(traceDir, { recursive: true });\n}\n\nexport async function openTrace(traceFile: string) {\n  const filePath = path.resolve(traceFile);\n  if (!fs.existsSync(filePath))\n    throw new Error(`Trace file not found: ${filePath}`);\n  await closeTrace();\n  await fs.promises.mkdir(traceDir, { recursive: true });\n  if (filePath.endsWith('.zip'))\n    await extractTrace(filePath, traceDir);\n  else\n    await fs.promises.writeFile(path.join(traceDir, '.link'), filePath, 'utf-8');\n}\n\nexport async function loadTrace(): Promise<LoadedTrace> {\n  const dir = ensureTraceOpen();\n  const linkFile = path.join(dir, '.link');\n  let traceDir: string;\n  let traceFile: string | undefined;\n  if (fs.existsSync(linkFile)) {\n    const tracePath = await fs.promises.readFile(linkFile, 'utf-8');\n    traceDir = path.dirname(tracePath);\n    traceFile = path.basename(tracePath);\n  } else {","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/tools/trace/traceUtils.ts#L51-L87","documentation":"Thrown by openTrace() when the resolved trace file path does not exist on disk (fs.existsSync returns false). The path is resolved with path.resolve before the check, so it is evaluated relative to the current working directory. This guards extractTrace and the trace loader from receiving a nonexistent input.","triggerScenarios":"Running `npx playwright trace open ./missing.zip` or any path that does not point to an existing file.","commonSituations":"Typo in the filename; relative path resolved from the wrong cwd; trace file was deleted or never downloaded; wrong path on CI vs local.","solutions":["Verify the file exists at the resolved path printed in the error.","Use an absolute path to the trace file to avoid cwd issues.","Re-download or re-generate the trace if it is missing."],"exampleFix":"// before\nnpx playwright trace open ./traces/run.zip\n// after\nnpx playwright trace open /home/user/project/traces/run.zip","handlingStrategy":"validation","validationCode":"import fs from 'fs';\nimport path from 'path';\nconst filePath = path.resolve(traceFile);\nif (!fs.existsSync(filePath)) {\n  throw new Error(`Trace file not found: ${filePath}`);\n}","typeGuard":"function isExistingFile(p: string): boolean {\n  try { return fs.statSync(p).isFile(); } catch { return false; }\n}","tryCatchPattern":null,"preventionTips":["Resolve trace file paths to absolute before invoking the CLI.","Verify downloads/copies completed before referencing the file.","Use the same path form (absolute) in CI and locally."],"tags":["trace","cli","filesystem","validation"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}