{"record":{"id":"072caf216e97f3c8","repo":"hashicorp/packer","slug":"failed-to-add-zip-header-for-s-s","errorCode":null,"errorMessage":"Failed to add zip header for %s: %s","messagePattern":"Failed to add zip header for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/compress/post-processor.go","lineNumber":427,"sourceCode":"\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 {\n\t\t\treturn fmt.Errorf(\"Unable to read file %s: %s\", path, err)\n\t\t}\n\t\tdefer source.Close()\n\n\t\ttarget, err := archive.Create(path)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to add zip header for %s: %s\", path, err)\n\t\t}\n\n\t\t_, err = io.Copy(target, source)\n\t\tif 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","sourceCodeStart":409,"sourceCodeEnd":437,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/compress/post-processor.go#L409-L437","documentation":"In createZipArchive, archive.Create(path) registers the file in the zip and writes its header. If the zip writer cannot create the entry (rare — usually the underlying writer already failed), this error is returned with the path and cause. The zip is abandoned.","triggerScenarios":"zip.Writer.Create returns an error — practically only when the output writer is broken (closed pipe, disk full) because Create itself only formats a header and defers writing.","commonSituations":"Output stream/pipe closed early (e.g. downstream writer already errored); disk full so a later flush fails and surfaces on a subsequent Create; corrupt or closed output file handle.","solutions":["Check disk space and writability of the compress post-processor's output path.","Re-run the build after fixing the output stream.","Look at the wrapped cause — it points at the actual writer failure.","Ensure no other step concurrently truncates or closes the output archive."],"exampleFix":"// before\n{\"type\": \"compress\", \"output\": \"/full-disk/a.zip\"}\n// after: point at a volume with free space\n{\"type\": \"compress\", \"output\": \"/data/artifacts/a.zip\"}","handlingStrategy":"validation","validationCode":"# preflight: writable output path with free space\n[ -w \"$(dirname \"$OUTPUT\")\" ] && [ \"$(df --output=avail -B1 \"$OUTPUT_DIR\" | tail -1)\" -gt \"$MIN_BYTES\" ] || exit 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guarantee free space on the archive output volume.","Ensure no concurrent process truncates the output file.","Keep output on reliable local storage.","Check the wrapped cause when this fires — it's a downstream writer failure."],"tags":["zip","archive","io","post-processor"],"backgroundTag":"archive-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"}