hashicorp/packer · error
error creating %s writer: %s
Error message
error creating %s writer: %s
What it means
The bgzf compression writer could not be created. makeBGZFWriter returns ErrInvalidCompressionLevel (or a bgzf library error) when bgzf.NewWriterLevel rejects the configured compression level or writer parameters, and PostProcess wraps it via the errTmpl message naming the algorithm.
Source
Thrown at post-processor/compress/post-processor.go:164
}
outputFile, err := os.Create(target)
if err != nil {
return nil, false, false, fmt.Errorf(
"Unable to create archive %s: %s", target, err)
}
defer outputFile.Close()
// Setup output interface. If we're using compression, output is a
// compression writer. Otherwise it's just a file.
var output io.WriteCloser
errTmpl := "error creating %s writer: %s"
switch p.config.Algorithm {
case "bgzf":
ui.Say(fmt.Sprintf("Using bgzf compression with %d cores for %s",
runtime.GOMAXPROCS(-1), target))
output, err = makeBGZFWriter(outputFile, p.config.CompressionLevel)
if err != nil {
return nil, false, false, fmt.Errorf(errTmpl, p.config.Algorithm, err)
}
defer output.Close()
case "bzip2":
ui.Say(fmt.Sprintf("Using bzip2 compression with 1 core for %s (library does not support MT)",
target))
output, err = makeBZIP2Writer(outputFile, p.config.CompressionLevel)
if err != nil {
return nil, false, false, fmt.Errorf(errTmpl, p.config.Algorithm, err)
}
defer output.Close()
case "lz4":
ui.Say(fmt.Sprintf("Using lz4 compression with %d cores for %s",
runtime.GOMAXPROCS(-1), target))
output, err = makeLZ4Writer(outputFile, p.config.CompressionLevel)
if err != nil {
return nil, false, false, fmt.Errorf(errTmpl, p.config.Algorithm, err)
}
defer output.Close()View on GitHub (pinned to eb36e3c3e4)
Solutions
- Set compression_level to an integer in -1..9 (or remove it to use the default)
- Run packer validate to catch the bad level before the build
- If using bgzf, confirm no config override injects a level outside the flate range
Example fix
// before algorithm = "bgzf" compression_level = 12 // after algorithm = "bgzf" compression_level = 9
Defensive patterns
Strategy: validation
Validate before calling
if cfg.CompressionLevel < -1 || cfg.CompressionLevel > 9 {
return fmt.Errorf("bgzf requires compression_level in -1..9, got %d", cfg.CompressionLevel)
} Try / catch
out, err := makeBGZFWriter(outputFile, cfg.CompressionLevel)
if errors.Is(err, compress.ErrInvalidCompressionLevel) {
// retry with default level
out, err = makeBGZFWriter(outputFile, -1)
} Prevention
- Keep compression_level within -1..9 when using bgzf
- Run packer validate to catch bad levels pre-build
- Omit compression_level to use defaults
When it happens
Trigger: Algorithm is "bgzf" and bgzf.NewWriterLevel(outputFile, p.config.CompressionLevel, runtime.GOMAXPROCS(-1)) returns an error — practically always an out-of-range compression_level (-2 or >9).
Common situations: Setting compression_level outside the gzip range for bgzf; passing a string/invalid value that survived config decoding as a bad integer; copy-pasted level from an lz4-specific config.
Related errors
- ErrInvalidCompressionLevel
- ErrWrongInputCount
- signing_mode %q requires signer
- build keyless identity policy: %w
- signing_mode %q requires keyless_identity and keyless_oidc_i
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/2f36e64d73e4264e.
Report an issue: GitHub.