{"record":{"id":"2c4fdec6c02990fd","repo":"avajs/ava","slug":"unexpected-snapshot-version","errorCode":null,"errorMessage":"Unexpected snapshot version","messagePattern":"Unexpected snapshot version","errorType":"exception","errorClass":"VersionMismatchError","httpStatus":null,"severity":"error","filePath":"lib/snapshot-manager.js","lineNumber":242,"sourceCode":"\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) {\n\tconst {compressed, sha256sumOffset, compressedOffset} = extractCompressedSnapshot(buffer, snapPath);\n\n\tconst sha256sum = crypto.createHash('sha256').update(compressed).digest();\n\tconst expectedSum = buffer.slice(sha256sumOffset, compressedOffset);\n\tif (!sha256sum.equals(expectedSum)) {\n\t\tthrow new ChecksumError(snapPath);","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/snapshot-manager.js#L224-L260","documentation":"AVA stamps each snapshot file with a format version number, read as a UInt16 after the header newline. When that stored version differs from the VERSION the running AVA supports, it throws VersionMismatchError, because the binary layout (hash/compressed offsets) cannot be trusted across versions.","triggerScenarios":"Reading a .snap file written by a newer or older AVA whose VERSION constant differs; mixing AVA versions (e.g. different versions in local node_modules vs CI lockfile) on the same snapshot files.","commonSituations":"Dowgrading AVA after snapshots were written by a newer release; parallel branches on different AVA versions sharing one snapshot directory; failing to update the lockfile in CI.","solutions":["Align AVA versions: update (or pin via lockfile) so the version that reads the snapshots matches the one that wrote them, then run --update-snapshots if needed","Delete stale .snap files and regenerate with npx ava --update-snapshots","Commit regenerated snapshots so all environments share the current version"],"exampleFix":"// before\nnpm install\n// after\nnpm install && npx ava --update-snapshots && git add test/snapshots","handlingStrategy":"validation","validationCode":"const buf = fs.readFileSync(snapPath);\nconst nl = buf.indexOf(0x0A);\nif (nl !== -1) {\n  const version = buf.readUInt16LE(nl + 1);\n  if (version !== CURRENT_VERSION) console.warn(`snapshot version ${version} != ${CURRENT_VERSION}; run --update-snapshots`);\n}","typeGuard":"function hasCompatibleVersion(buffer, expected) {\n  const nl = buffer.indexOf(0x0A);\n  return nl !== -1 && buffer.readUInt16LE(nl + 1) === expected;\n}","tryCatchPattern":"try {\n  decodeSnapshots(buffer, snapPath);\n} catch (err) {\n  if (/Unexpected snapshot version/i.test(err.message)) {\n    // align AVA versions across environments, then npx ava --update-snapshots\n  } else { throw err; }\n}","preventionTips":["Use the same AVA version everywhere via a committed lockfile","After any AVA upgrade, regenerate and commit snapshots","Keep snapshot-writing and snapshot-reading environments on one release line"],"tags":["snapshots","version-mismatch","upgrade"],"backgroundTag":"snapshot-version-mismatch","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}