{"record":{"id":"1ba3538c38c457ba","repo":"vitest-dev/vitest","slug":"snapshot-file-id-does-not-exist","errorCode":null,"errorMessage":"Snapshot file \"${id}\" does not exist.","messagePattern":"Snapshot file \"(.+?)\" does not exist\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/browser/src/node/rpc.ts","lineNumber":299,"sourceCode":"          if (!canWrite(project)) {\n            vitest.logger.error(\n              `[vitest] Cannot save snapshot file \"${id}\". File writing is disabled because server is exposed to the internet, see https://vitest.dev/config/api.`,\n            )\n            return\n          }\n          await fs.mkdir(dirname(id), { recursive: true })\n          await fs.writeFile(id, content, 'utf-8')\n        },\n        async removeSnapshotFile(id) {\n          checkFileAccess(id)\n          if (!canWrite(project)) {\n            vitest.logger.error(\n              `[vitest] Cannot remove snapshot file \"${id}\". File writing is disabled because server is exposed to the internet, see https://vitest.dev/config/api.`,\n            )\n            return\n          }\n          if (!existsSync(id)) {\n            throw new Error(`Snapshot file \"${id}\" does not exist.`)\n          }\n          await fs.unlink(id)\n        },\n        getBrowserFileSourceMap(id) {\n          const mod = globalServer.vite.moduleGraph.getModuleById(id)\n          const result = mod?.transformResult\n          // handle non-inline source map such as pre-bundled deps in node_modules/.vite\n          if (result && !result.map) {\n            const filePath = id.split('?')[0]\n            const extracted = extractSourcemapFromFile(result.code, filePath)\n            return extracted?.map\n          }\n          return result?.map\n        },\n        cancelCurrentRun(reason) {\n          vitest.cancelCurrentRun(reason)\n        },\n        async resolveId(id, importer) {","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/browser/src/node/rpc.ts#L281-L317","documentation":"removeSnapshotFile checks existsSync(id) before calling fs.unlink and throws if the file is absent. The guard prevents an ENOENT from unlink, surfacing a clearer message. It runs after checkFileAccess and the canWrite guard, so it indicates the file was simply not there to remove.","triggerScenarios":"Calling the removeSnapshotFile RPC (typically via snapshot cleanup tooling) with a path to a snapshot that was already deleted, never written, or whose name differs from what was passed.","commonSituations":"Running snapshot cleanup twice; passing a snapshot id with a different extension (.snap vs the file path); a previous test run that failed before writing the snapshot; manual deletion of the snapshot file between operations.","solutions":["Check existence before requesting removal, or catch the error and treat it as a no-op.","Verify the id passed matches an actual on-disk snapshot path.","Avoid running concurrent snapshot cleanups that race on the same file."],"exampleFix":"// before\nawait rpc.removeSnapshotFile(id) // throws if absent\n// after\nimport { existsSync } from 'node:fs'\nif (existsSync(id)) await rpc.removeSnapshotFile(id)","handlingStrategy":"validation","validationCode":"import { existsSync } from 'node:fs'\nfunction snapshotExists(id: string): boolean { return existsSync(id) }","typeGuard":null,"tryCatchPattern":"try { await rpc.removeSnapshotFile(id) }\ncatch (e) {\n  if (e instanceof Error && e.message.includes('does not exist')) return // idempotent\n  throw e\n}","preventionTips":["Guard removal calls with existsSync when callers may invoke them more than once.","Make cleanup tooling idempotent by catching the not-exist error.","Avoid concurrent cleanups on the same snapshot path."],"tags":["snapshot","filesystem","idempotency","browser"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}