{"record":{"id":"ba5f4ababb00d87a","repo":"hashicorp/nomad","slug":"failed-to-write-snapshot-metadata-header-v","errorCode":null,"errorMessage":"failed to write snapshot metadata header: %v","messagePattern":"failed to write snapshot metadata header: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helper/snapshot/archive.go","lineNumber":124,"sourceCode":"\t// Create a hash list that we will use to write a SHA256SUMS file into\n\t// the archive.\n\thl := newHashList()\n\n\t// Encode the snapshot metadata, which we need to feed back during a\n\t// restore.\n\tmetaHash := hl.Add(\"meta.json\")\n\tvar metaBuffer bytes.Buffer\n\tenc := json.NewEncoder(&metaBuffer)\n\tif err := enc.Encode(metadata); err != nil {\n\t\treturn fmt.Errorf(\"failed to encode snapshot metadata: %v\", err)\n\t}\n\tif err := archive.WriteHeader(&tar.Header{\n\t\tName:    \"meta.json\",\n\t\tMode:    0600,\n\t\tSize:    int64(metaBuffer.Len()),\n\t\tModTime: now,\n\t}); err != nil {\n\t\treturn fmt.Errorf(\"failed to write snapshot metadata header: %v\", err)\n\t}\n\tif _, err := io.Copy(archive, io.TeeReader(&metaBuffer, metaHash)); err != nil {\n\t\treturn fmt.Errorf(\"failed to write snapshot metadata: %v\", err)\n\t}\n\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}","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/snapshot/archive.go#L106-L142","documentation":"write() adds the meta.json tar header before writing its bytes. This error wraps a failure writing that tar header to the underlying archive writer. It indicates the destination writer rejected the header write.","triggerScenarios":"archive.WriteHeader fails because the underlying io.Writer returned an error: disk full, closed writer, broken pipe on a network sink, or an invalid header (negative size).","commonSituations":"Writing a snapshot to a full disk, to an already-closed file, or over a failed network stream.","solutions":["Check and free disk space on the destination","Verify the destination writer is open and healthy for the duration of write()","Inspect the wrapped error (%v) for the root cause (e.g. 'no space left on device')"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if fi, err := dest.Stat(); err == nil && fi.Size() >= totalExpectedSize {\n    // destination has room\n}","typeGuard":null,"tryCatchPattern":"if err := write(archive, metadata, snap); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) || strings.Contains(err.Error(), \"no space left\") {\n        return fmt.Errorf(\"destination write failed: %w\", err)\n    }\n    return err\n}","preventionTips":["Check free disk space before writing snapshots","Keep the destination writer open until write() returns","Wrap sinks (files/sockets) with explicit close-error checks"],"tags":["tar","io","disk"],"backgroundTag":"disk-full","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"}