{"record":{"id":"cead2129653f1193","repo":"hashicorp/nomad","slug":"failed-to-read-snapshot-w","errorCode":null,"errorMessage":"failed to read snapshot: %w","messagePattern":"failed to read snapshot: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/operator_snapshot_inspect.go","lineNumber":186,"sourceCode":"\treturn 0\n}\n\nfunc inspect(file io.Reader) (*raft.SnapshotMeta, *SnapshotInfo, error) {\n\tinfo := &SnapshotInfo{\n\t\tStats:     make(map[nomad.SnapshotType]typeStats),\n\t\tTotalSize: 0,\n\t}\n\n\t// w is closed by CopySnapshot\n\tr, w := io.Pipe()\n\tcr := &countingReader{wrappedReader: r}\n\terrCh := make(chan error)\n\tmetaCh := make(chan *raft.SnapshotMeta)\n\n\tgo func() {\n\t\tmeta, err := snapshot.CopySnapshot(file, w)\n\t\tif err != nil {\n\t\t\terrCh <- fmt.Errorf(\"failed to read snapshot: %w\", err)\n\t\t} else {\n\t\t\tmetaCh <- meta\n\t\t}\n\t}()\n\n\thandler := func(header *nomad.SnapshotHeader, snapType nomad.SnapshotType, dec *codec.Decoder) error {\n\t\tname := snapType.String()\n\t\tstat := info.Stats[snapType]\n\n\t\tif stat.Name == \"\" {\n\t\t\tstat.Name = name\n\t\t}\n\n\t\tvar val any\n\t\terr := dec.Decode(&val)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to decode snapshot %q: %v\", snapType, err)\n\t\t}","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/operator_snapshot_inspect.go#L168-L204","documentation":"`nomad operator snapshot inspect` copies the raft snapshot archive to a writer in a goroutine via snapshot.CopySnapshot. If reading/unarchiving the snapshot file fails (corrupt archive, truncated file, wrong file type), the error is wrapped with this message and sent to the caller.","triggerScenarios":"Inspecting a snapshot file that is not a valid raft snapshot archive, is truncated/corrupted, or is unreadable at the byte level so CopySnapshot returns an error.","commonSituations":"Pointing the command at a different output file (e.g. a backup tarball or partial download), snapshots damaged during transfer from the server, or snapshots saved by an incompatible Nomad/raft version.","solutions":["Re-take the snapshot with `nomad operator snapshot save` and inspect the new file.","Verify the file is a genuine Nomad raft snapshot (check size/checksum vs the original, re-transfer if copied over the network).","Check the wrapped error (%w cause) for the underlying reason — e.g. bad archive header vs I/O error.","Confirm the Nomad version producing the snapshot matches the CLI version used to inspect it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const stat = fs.statSync(snapshotPath); if (stat.size === 0 || stat.size < 512) throw new Error('file too small to be a raft snapshot'); const magic = fs.readFileSync(snapshotPath).slice(0, 4).toString(); if (magic.includes('PK') === false && magic.charCodeAt(0) === 0x1f) throw new Error('not a snapshot archive');","typeGuard":null,"tryCatchPattern":"try { inspectSnapshot(file) } catch (e) { if (String(e).includes('failed to read snapshot')) { console.error('Snapshot file corrupt or not a raft snapshot; re-run: nomad operator snapshot save'); } throw e; }","preventionTips":["Always take snapshots via `nomad operator snapshot save`, not ad-hoc raft tooling.","Verify file size/checksum after transferring snapshots between machines.","Match CLI version to the server version that wrote the snapshot."],"tags":["raft","snapshot","io","nomad"],"backgroundTag":"corrupt-snapshot-file","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}