{"record":{"id":"b75f4c744d60ef65","repo":"avajs/ava","slug":"invalid-snapshot-file","errorCode":null,"errorMessage":"Invalid snapshot file","messagePattern":"Invalid snapshot file","errorType":"exception","errorClass":"InvalidSnapshotError","httpStatus":null,"severity":"error","filePath":"lib/snapshot-manager.js","lineNumber":236,"sourceCode":"\tconst sha256sum = crypto.createHash('sha256').update(compressed).digest();\n\treturn Buffer.concat([\n\t\tREADABLE_PREFIX,\n\t\tVERSION_HEADER,\n\t\tsha256sum,\n\t\tcompressed,\n\t], READABLE_PREFIX.byteLength + VERSION_HEADER.byteLength + SHA_256_HASH_LENGTH + compressed.byteLength);\n}\n\nexport function extractCompressedSnapshot(buffer, snapPath) {\n\tif (isLegacySnapshot(buffer)) {\n\t\tthrow new LegacyError(snapPath);\n\t}\n\n\t// The version starts after the readable prefix, which is ended by a newline\n\t// byte (0x0A).\n\tconst newline = buffer.indexOf(0x0A);\n\tif (newline === -1) {\n\t\tthrow new InvalidSnapshotError(snapPath);\n\t}\n\n\tconst versionOffset = newline + 1;\n\tconst version = buffer.readUInt16LE(versionOffset);\n\tif (version !== VERSION) {\n\t\tthrow new VersionMismatchError(snapPath, version);\n\t}\n\n\tconst sha256sumOffset = versionOffset + 2;\n\tconst compressedOffset = sha256sumOffset + SHA_256_HASH_LENGTH;\n\tconst compressed = buffer.slice(compressedOffset);\n\n\treturn {\n\t\tversion, compressed, sha256sumOffset, compressedOffset,\n\t};\n}\n\nfunction decodeSnapshots(buffer, snapPath) {","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/snapshot-manager.js#L218-L254","documentation":"This invalid-snapshot error means the snapshot file does not have the structure AVA expects: the reader could not find the newline byte (0x0A) that terminates the readable prefix header. Without that delimiter AVA cannot locate the version field, so the file is treated as corrupt and extractCompressedSnapshot() throws InvalidSnapshotError.","triggerScenarios":"Calling extractCompressedSnapshot/decodeSnapshots on a buffer with no 0x0A byte in the header region — e.g. a truncated, hand-edited, binary-corrupted, or entirely foreign .snap file (line-ending conversion that removed the newline, git filters, or partial file writes).","commonSituations":"Git autocrlf or other line-ending filters mangling committed snapshot files; disk truncation; someone editing the .snap file by hand; opening a snapshot file produced by a different tool.","solutions":["Regenerate the file: delete the corrupt .snap and rerun AVA with --update-snapshots","Check gitattributes/line-ending config so .snap files are not altered (add '*. -text' or mark snapshots binary) and restore the original via git checkout -- <file>.snap","Restore the file from version control or a backup if it was truncated or hand-edited"],"exampleFix":"// before (.gitattributes missing)\n// after (.gitattributes)\n*.snap -text\n*.snap binary","handlingStrategy":"validation","validationCode":"const buf = fs.readFileSync(snapPath);\nif (buf.indexOf(0x0A) === -1) {\n  throw new Error(`${snapPath} has no header newline — corrupt or wrong format; regenerate with --update-snapshots`);\n}","typeGuard":"function looksLikeAvaSnapshot(buffer) {\n  return Buffer.isBuffer(buffer) && buffer.indexOf(0x0A) !== -1;\n}","tryCatchPattern":"try {\n  decodeSnapshots(buffer, snapPath);\n} catch (err) {\n  if (/Invalid snapshot file/i.test(err.message)) {\n    // restore from git or regenerate with --update-snapshots\n  } else { throw err; }\n}","preventionTips":["Mark *.snap as binary/-text in .gitattributes to stop line-ending filters","Never edit .snap files by hand","Check file size after checkout/CI artifact transfer to catch truncation early"],"tags":["snapshots","corruption","file-format"],"backgroundTag":"corrupt-snapshot-file","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}