{"record":{"id":"19725c7e1ed2226b","repo":"hashicorp/packer","slug":"failed-to-write-tar-header-for-s-s","errorCode":null,"errorMessage":"Failed to write tar header for %s: %s","messagePattern":"Failed to write tar header for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/compress/post-processor.go","lineNumber":402,"sourceCode":"\t\t\treturn fmt.Errorf(\"Unable to read file %s: %s\", path, err)\n\t\t}\n\t\tdefer file.Close()\n\n\t\tfi, err := file.Stat()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Unable to get fileinfo for %s: %s\", path, err)\n\t\t}\n\n\t\theader, err := tar.FileInfoHeader(fi, path)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to create tar header for %s: %s\", path, err)\n\t\t}\n\n\t\t// workaround for archive format on go >=1.10\n\t\tsetHeaderFormat(header)\n\n\t\tif err := archive.WriteHeader(header); err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to write tar header for %s: %s\", path, err)\n\t\t}\n\n\t\tif _, err := io.Copy(archive, file); err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to copy %s data to archive: %s\", path, err)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc createZipArchive(files []string, output io.WriteCloser) error {\n\tarchive := zip.NewWriter(output)\n\tdefer archive.Close()\n\n\tfor _, path := range files {\n\t\tpath = filepath.ToSlash(path)\n\n\t\tsource, err := os.Open(path)\n\t\tif err != nil {","sourceCodeStart":384,"sourceCodeEnd":420,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/compress/post-processor.go#L384-L420","documentation":"The compress post-processor's createTarArchive writes each file into the tar stream: it first writes the tar header via archive.WriteHeader(header). When the underlying archive/tar writer reports a write failure (or invalid header), the post-processor wraps it in this error with the file path and cause. The archive build aborts and the post-processor fails.","triggerScenarios":"tar.Writer.WriteHeader returns an error — typically because the writer's underlying pipe/compression stream is broken or closed, the header is invalid (e.g. unsupported typeflag for the format), or the previous io.Copy left the writer in an error state.","commonSituations":"Disk full or output stream broken mid-archive; compression writer (gzip/etc.) already failed and the error surfaced on the next header write; extremely large files pushing header fields (size) beyond the selected tar format limits; running on go <1.10 where setHeaderFormat behavior differs.","solutions":["Check free disk space and permissions on the output artifact path; a full/broken output stream is the most common root cause.","Re-run the build; transient stream/pipe failures disappear on retry once the environment is healthy.","Inspect the wrapped cause (%s at the end) — it names the real tar/compression writer error.","If the file path is special (device node, very long name), archive it via a format/level that supports it, or exclude it from the artifact."],"exampleFix":"// before\n\"post-processors\": [[{\"type\": \"compress\", \"output\": \"/mnt/ro/artifact.tar.gz\"}]]\n// after (writable output path)\n\"post-processors\": [[{\"type\": \"compress\", \"output\": \"output/artifact.tar.gz\"}]]","handlingStrategy":"validation","validationCode":"// preflight: ensure output location is writable and has space\nconst output = \"output/artifact.tar.gz\"\nif fs.statSync(path.dirname(output)).sizeHintCheck === false { /* abort */ }\nfs.accessSync(path.dirname(output), fs.constants.W_OK)","typeGuard":null,"tryCatchPattern":"// shell: fail fast and surface wrapped cause\npacker build template.pkr.hcl || { df -h .; exit 1; }","preventionTips":["Keep compress output on a volume with free space >= artifact size.","Check `df -h` before large builds in CI.","Don't point output at pipes or flaky network mounts.","Read the wrapped cause in the error for the real writer failure."],"tags":["archive","tar","post-processor","io"],"backgroundTag":"tar-header-write-failed","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}