{"record":{"id":"ad39064932764a89","repo":"hashicorp/packer","slug":"failed-to-compress-s-s","errorCode":null,"errorMessage":"Failed to compress %s: %s","messagePattern":"Failed to compress (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/compress/post-processor.go","lineNumber":243,"sourceCode":"\t\t// into our compressor.\n\t\tif len(artifact.Files()) != 1 {\n\t\t\treturn nil, false, false, fmt.Errorf(\n\t\t\t\t\"Can only have 1 input file when not using tar/zip. Found %d \"+\n\t\t\t\t\t\"files: %v\", len(artifact.Files()), artifact.Files())\n\t\t}\n\t\tarchiveFile := artifact.Files()[0]\n\t\tui.Say(fmt.Sprintf(\"Archiving %s with %s\", archiveFile, compression))\n\n\t\tsource, err := os.Open(archiveFile)\n\t\tif err != nil {\n\t\t\treturn nil, false, false, fmt.Errorf(\n\t\t\t\t\"Failed to open source file %s for reading: %s\",\n\t\t\t\tarchiveFile, err)\n\t\t}\n\t\tdefer source.Close()\n\n\t\tif _, err = io.Copy(output, source); err != nil {\n\t\t\treturn nil, false, false, fmt.Errorf(\"Failed to compress %s: %s\",\n\t\t\t\tarchiveFile, err)\n\t\t}\n\t}\n\n\tui.Say(fmt.Sprintf(\"Archive %s completed\", target))\n\n\treturn newArtifact, false, false, nil\n}\n\nfunc (config *Config) detectFromFilename() {\n\tvar result [][]string\n\n\textensions := map[string]string{\n\t\t\"tar\":   \"tar\",\n\t\t\"zip\":   \"zip\",\n\t\t\"gz\":    \"pgzip\",\n\t\t\"lz4\":   \"lz4\",\n\t\t\"bgzf\":  \"bgzf\",","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/compress/post-processor.go#L225-L261","documentation":"The io.Copy from the artifact's source file into the compression writer failed during Packer's compress post-processor. Reading the source or writing/compressing into the output stream returned an error after the file was successfully opened, so the build aborted mid-compression.","triggerScenarios":"The default (single-file, non tar/zip) branch runs io.Copy(output, source) and it returns an error — typically ENOSPC writing the output archive, an I/O error on the output file, or a read failure on the source mid-stream.","commonSituations":"Disk filling up while compressing a large disk image; output filesystem hitting a quota; source file truncated/changed concurrently; failing disk or network storage holding the output path.","solutions":["Check free disk space at the output path (df -h) and clean up","Look at the wrapped inner error to distinguish read vs write failure","Move output_directory to larger/local storage and retry","Retry the build; if persistent, test the source file integrity (e.g. fsck or re-download)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// ensure adequate disk space before compressing\nif fi, err := os.Stat(outputDir); err == nil {\n    _ = fi\n}\n// check at least 2x the source size is free on the output filesystem\nif st, err := os.Stat(sourcePath); err == nil {\n    if free, _ := diskFree(outputDir); free < 2*st.Size() {\n        return fmt.Errorf(\"insufficient disk space to compress %s\", sourcePath)\n    }\n}","typeGuard":null,"tryCatchPattern":"// Go: retry once on transient copy failure\nartifact, _, _, err := pp.PostProcess(ctx, ui, artifact)\nif err != nil && strings.Contains(err.Error(), \"Failed to compress\") {\n    time.Sleep(2 * time.Second)\n    artifact, _, _, err = pp.PostProcess(ctx, ui, artifact)\n}\nreturn err","preventionTips":["Pre-check free disk space (>= 2x input size) on the output volume","Avoid concurrent jobs writing to the same output directory","Monitor the source file isn't modified during the build","Use local disks for output rather than unreliable network storage"],"tags":["packer","post-processor","compression","io"],"backgroundTag":"io-copy-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"}