{"record":{"id":"899b48508846516b","repo":"hashicorp/nomad","slug":"failed-to-encode-snapshot-hashes-v","errorCode":null,"errorMessage":"failed to encode snapshot hashes: %v","messagePattern":"failed to encode snapshot hashes: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helper/snapshot/archive.go","lineNumber":147,"sourceCode":"\n\t// Copy the snapshot data given the size from the metadata.\n\tsnapHash := hl.Add(\"state.bin\")\n\tif err := archive.WriteHeader(&tar.Header{\n\t\tName:    \"state.bin\",\n\t\tMode:    0600,\n\t\tSize:    metadata.Size,\n\t\tModTime: now,\n\t}); err != nil {\n\t\treturn fmt.Errorf(\"failed to write snapshot data header: %v\", err)\n\t}\n\tif _, err := io.CopyN(archive, io.TeeReader(snap, snapHash), metadata.Size); err != nil {\n\t\treturn fmt.Errorf(\"failed to write snapshot metadata: %v\", err)\n\t}\n\n\t// Create a SHA256SUMS file that we can use to verify on restore.\n\tvar shaBuffer bytes.Buffer\n\tif err := hl.Encode(&shaBuffer); err != nil {\n\t\treturn fmt.Errorf(\"failed to encode snapshot hashes: %v\", err)\n\t}\n\tif err := archive.WriteHeader(&tar.Header{\n\t\tName:    \"SHA256SUMS\",\n\t\tMode:    0600,\n\t\tSize:    int64(shaBuffer.Len()),\n\t\tModTime: now,\n\t}); err != nil {\n\t\treturn fmt.Errorf(\"failed to write snapshot hashes header: %v\", err)\n\t}\n\tif _, err := io.Copy(archive, &shaBuffer); err != nil {\n\t\treturn fmt.Errorf(\"failed to write snapshot metadata: %v\", err)\n\t}\n\n\t// Finalize the archive.\n\tif err := archive.Close(); err != nil {\n\t\treturn fmt.Errorf(\"failed to finalize snapshot: %v\", err)\n\t}\n","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/snapshot/archive.go#L129-L165","documentation":"Fires while writing a Nomad snapshot archive: encoding the SHA256SUMS hash list (hl.Encode) into the tar failed, so the archive is left without integrity data and the snapshot stream errors out.","triggerScenarios":"hashList.Encode fails, e.g. the internal hash values cannot be marshaled (hex/JSON encoding error) or the target buffer writer errors.","commonSituations":"Custom/modified hash list code, or an in-memory buffer write failure (very rare).","solutions":["Inspect the wrapped error for the exact encoding cause","Ensure hashes were added via hl.Add with standard sha256 hashers","Avoid modifying hashList internals; regenerate the snapshot"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := write(archive, metadata, snap); err != nil {\n    if strings.Contains(err.Error(), \"failed to encode snapshot hashes\") {\n        return fmt.Errorf(\"hash list encoding failed: %w\", err)\n    }\n    return err\n}","preventionTips":["Use stock hl.Add/hl.Encode APIs without modification","Keep the hash list buffer allocation generous","Test write() round-trip with DecodeAndVerify in CI"],"tags":["encoding","hashlist","snapshot"],"backgroundTag":"encode-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}