goreleaser/goreleaser · error
failed to close archive file %s: %w
Error message
failed to close archive file %s: %w
What it means
After writing archive contents, goreleaser wraps the archive file Close() call; if closing fails (and no earlier error occurred) it rewrites the error with this message. Close failures indicate buffered data could not be fully flushed to disk.
Source
Thrown at internal/pipe/archive/archive.go:199
archivePath := filepath.Join(ctx.Config.Dist, folder+"."+format)
lock.Lock()
if err := os.MkdirAll(filepath.Dir(archivePath), 0o755|os.ModeDir); err != nil {
lock.Unlock()
return err
}
if _, err = os.Stat(archivePath); !errors.Is(err, fs.ErrNotExist) {
lock.Unlock()
return fmt.Errorf("archive named %s already exists. Check your archive name template", archivePath)
}
archiveFile, err := os.Create(archivePath)
if err != nil {
lock.Unlock()
return fmt.Errorf("failed to create directory %s: %w", archivePath, err)
}
lock.Unlock()
defer func() {
if closeErr := archiveFile.Close(); err == nil && closeErr != nil {
err = fmt.Errorf("failed to close archive file %s: %w", archivePath, closeErr)
}
}()
log := log.WithField("name", archivePath)
log.Info("archiving")
wrap, err := template.Apply(wrapFolder(arch))
if err != nil {
return err
}
a, err := archive.New(archiveFile, format)
if err != nil {
return err
}
a = NewEnhancedArchive(a, wrap)
defer func() {
if closeErr := a.Close(); err == nil && closeErr != nil {
err = fmt.Errorf("failed to close archive %s: %w", archivePath, closeErr)View on GitHub (pinned to f5edd73956)
Solutions
- Free disk space and re-run with --clean
- Archive to a local disk instead of a network mount for dist/
- Check ulimit -n / file descriptor limits when archiving many artifacts
- Re-run the release; transient I/O errors usually do not recur
Example fix
// before (CI) runs-on: macos-latest # small disk, large archives // after (CI) # free space or pick a runner with more disk before running goreleaser
Defensive patterns
Strategy: retry
Validate before calling
df -h . | awk 'NR==2 {print $4}' # require adequate free space
ulimit -n # check descriptor limits Try / catch
if strings.Contains(err.Error(), "failed to close archive") {
// free disk space, then re-run the release
return retryRelease()
} Prevention
- Keep dist/ on local disk, not NFS/network mounts
- Monitor disk space in CI before large releases
- Re-run transient I/O failures once before investigating
When it happens
Trigger: The underlying archive/archiveg writer returns an error on Close — typically ENOSPC while flushing the gzip/zip buffer, I/O error on the file descriptor, or an EnhancedArchive wrapper Close error.
Common situations: Disk filling up mid-release on CI runners; NFS/network filesystems dropping during large archives; file descriptor exhaustion (EMFILE) after many archives in one run.
Related errors
- could not close package file: %w
- node: write sea-config.json: %w
- archive named %s already exists. Check your archive name tem
- failed to create directory %s: %w
- failed to close archive %s: %w
AI-assisted analysis of goreleaser/goreleaser@f5edd73956 (2026-09-05).
Data as JSON: /api/errors/a62d2a872858602b.
Report an issue: GitHub.