hashicorp/packer · error
Failed to compress %s: %s
Error message
Failed to compress %s: %s
What it means
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.
Source
Thrown at post-processor/compress/post-processor.go:243
// into our compressor.
if len(artifact.Files()) != 1 {
return nil, false, false, fmt.Errorf(
"Can only have 1 input file when not using tar/zip. Found %d "+
"files: %v", len(artifact.Files()), artifact.Files())
}
archiveFile := artifact.Files()[0]
ui.Say(fmt.Sprintf("Archiving %s with %s", archiveFile, compression))
source, err := os.Open(archiveFile)
if err != nil {
return nil, false, false, fmt.Errorf(
"Failed to open source file %s for reading: %s",
archiveFile, err)
}
defer source.Close()
if _, err = io.Copy(output, source); err != nil {
return nil, false, false, fmt.Errorf("Failed to compress %s: %s",
archiveFile, err)
}
}
ui.Say(fmt.Sprintf("Archive %s completed", target))
return newArtifact, false, false, nil
}
func (config *Config) detectFromFilename() {
var result [][]string
extensions := map[string]string{
"tar": "tar",
"zip": "zip",
"gz": "pgzip",
"lz4": "lz4",
"bgzf": "bgzf",View on GitHub (pinned to eb36e3c3e4)
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)
Defensive patterns
Strategy: retry
Validate before calling
// ensure adequate disk space before compressing
if fi, err := os.Stat(outputDir); err == nil {
_ = fi
}
// check at least 2x the source size is free on the output filesystem
if st, err := os.Stat(sourcePath); err == nil {
if free, _ := diskFree(outputDir); free < 2*st.Size() {
return fmt.Errorf("insufficient disk space to compress %s", sourcePath)
}
} Try / catch
// Go: retry once on transient copy failure
artifact, _, _, err := pp.PostProcess(ctx, ui, artifact)
if err != nil && strings.Contains(err.Error(), "Failed to compress") {
time.Sleep(2 * time.Second)
artifact, _, _, err = pp.PostProcess(ctx, ui, artifact)
}
return err Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The post-processor %s is unknown by Packer, and is likely pa
- error initializing post-processor '%s': %s
- post-processor type not found: %s
- No files specified in artifice configuration
- Unrecognized checksum type: %s
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/ad39064932764a89.
Report an issue: GitHub.