{"record":{"id":"7eee66f32aba52f7","repo":"vitest-dev/vitest","slug":"raw-snapshot-is-required","errorCode":null,"errorMessage":"Raw snapshot is required","messagePattern":"Raw snapshot is required","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/snapshot/src/client.ts","lineNumber":348,"sourceCode":"      received: stableResult.rendered,\n      expectedSnapshot,\n      matchResult,\n      isInline,\n      error,\n      assertionName: options.assertionName,\n    })\n\n    return {\n      pass,\n      message: () => `Snapshot \\`${key}\\` mismatched`,\n      actual: actual?.trim(),\n      expected: expected?.trim(),\n    }\n  }\n\n  async assertRaw(options: AssertOptions): Promise<void> {\n    if (!options.rawSnapshot) {\n      throw new Error('Raw snapshot is required')\n    }\n\n    const { filepath, rawSnapshot } = options\n\n    if (rawSnapshot.content == null) {\n      if (!filepath) {\n        throw new Error('Snapshot cannot be used outside of test')\n      }\n\n      const snapshotState = this.getSnapshotState(filepath)\n\n      // save the filepath, so it don't lose even if the await make it out-of-context\n      options.filepath ||= filepath\n      // resolve and read the raw snapshot file\n      rawSnapshot.file = await snapshotState.environment.resolveRawPath(\n        filepath,\n        rawSnapshot.file,\n      )","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/snapshot/src/client.ts#L330-L366","documentation":"SnapshotClient.assertRaw requires options.rawSnapshot (a raw snapshot descriptor with a file and content). If absent, the method cannot perform a raw snapshot comparison and throws immediately, before touching filepath.","triggerScenarios":"Calling assertRaw without a rawSnapshot option; passing a plain string instead of a { file, content } raw snapshot descriptor; invoking the raw API from a path that did not build the rawSnapshot object.","commonSituations":"Using the raw snapshot API (e.g. for non-serialized file content like images/text) without constructing the rawSnapshot descriptor; wrapper that drops rawSnapshot when forwarding options.","solutions":[],"exampleFix":"// before\nclient.assertRaw({ filepath, name: 'raw' })\n// after\nclient.assertRaw({ filepath, name: 'raw', rawSnapshot: { file: './snap.txt', content: null } })","handlingStrategy":"validation","validationCode":"if (!options.rawSnapshot || typeof options.rawSnapshot !== 'object') {\n  throw new Error('assertRaw requires a rawSnapshot descriptor { file, content }')\n}\nclient.assertRaw(options)","typeGuard":"function isRawSnapshot(v: unknown): v is { file: string; content: string | null } { return !!v && typeof v === 'object' && typeof (v as any).file === 'string' }","tryCatchPattern":null,"preventionTips":["Always construct a rawSnapshot descriptor at the call site","Do not pass plain strings where a descriptor is expected","Validate rawSnapshot shape in adapter wrappers"],"tags":["snapshot","raw","validation"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}