goreleaser/goreleaser · error
xz: failed to add %s, only one file can be archived in xz fo
Error message
xz: failed to add %s, only one file can be archived in xz format
What it means
The xz archive format is a single-stream container that holds exactly one file, unlike zip/tar which support multiple entries. Archive.Add tracks the first file added via a.name and refuses any subsequent Add call so it doesn't silently overwrite or corrupt the stream. This is a format limitation enforced explicitly by goreleaser's xz archive implementation.
Source
Thrown at pkg/archive/xz/xz.go:36
}
// New xz archive.
func New(target io.Writer) *Archive {
xzw, _ := xz.WriterConfig{DictCap: 16 * 1024 * 1024}.NewWriter(target)
return &Archive{
xzw: xzw,
}
}
// Close all closeables.
func (a *Archive) Close() error {
return a.xzw.Close()
}
// Add file to the archive.
func (a *Archive) Add(f config.File) error {
if a.name != "" {
return fmt.Errorf("xz: failed to add %s, only one file can be archived in xz format", f.Destination)
}
file, err := os.Open(f.Source) // #nosec
if err != nil {
return err
}
defer file.Close()
info, err := file.Stat()
if err != nil {
return err
}
if info.IsDir() {
return nil
}
a.name = f.DestinationView on GitHub (pinned to f5edd73956)
Solutions
- Change the archive format to tar.xz (format: tar.xz) which supports multiple files, instead of raw xz
- Keep only a single file in the `files:` list when using format: xz
- Split the archives: use format_overrides or multiple archives entries so each xz archive wraps exactly one file
Example fix
// before (.goreleaser.yaml)
archives:
- formats: [xz]
files: [bin/myapp, LICENSE]
// after
archives:
- formats: [tar.xz]
files: [bin/myapp, LICENSE] Defensive patterns
Strategy: validation
Validate before calling
// before creating the xz archive
if len(files) > 1 {
return fmt.Errorf("xz format supports only one file; got %d — use tar.xz instead", len(files))
} Try / catch
// Go: treat as unrecoverable config error
if err := a.Add(f); err != nil {
if strings.Contains(err.Error(), "only one file can be archived in xz format") {
return fmt.Errorf("config error: %w", err) // do not retry
}
return err
} Prevention
- Never configure format: xz with more than one file; prefer tar.xz for multi-file archives
- Count resolved files (after glob expansion) before adding them to the archive
- Add a config validation step in CI (goreleaser check) to catch bad archive configs
When it happens
Trigger: Calling Archive.Add(f config.File) a second time on the same *xz.Archive instance, i.e. after one successful Add (a.name is non-empty), or when the archive config produces multiple files for an xz-format archive.
Common situations: A goreleaser .goreleaser.yaml config where `format: xz` is combined with `files:` listing more than one file (or a glob that expands to several files); devs mistakenly treating xz like tar.gz and adding many files.
Related errors
- failed to apply template %s: %w
- globbing failed for pattern %s: %w
- failed to parse %s: %w
- invalid goos: %s
- invalid goarch: %s
AI-assisted analysis of goreleaser/goreleaser@f5edd73956 (2026-09-05).
Data as JSON: /api/errors/aa8895a871173be9.
Report an issue: GitHub.