goreleaser/goreleaser · error

failed to write to file: %w

Error message

failed to write to file: %w

What it means

goreleaser's universal binary pipe (macOS fat binary creation) wraps any error returned by binary.Write when writing the big-endian fat header into the output file. This means the low-level write to the newly created output file (in dist/) failed, typically due to disk, I/O, or file-descriptor problems. It is a filesystem-level failure, not a configuration error.

Source

Thrown at internal/pipe/universalbinary/universalbinary.go:210

	}

	// Build a fat_header.
	hdr := []uint32{macho.MagicFat, uint32(len(inputs))}

	// Build a fat_arch for each input file.
	for _, i := range inputs {
		hdr = append(hdr, i.cpu)
		hdr = append(hdr, i.subcpu)
		hdr = append(hdr, uint32(i.offset))
		hdr = append(hdr, uint32(len(i.data)))
		hdr = append(hdr, alignBits)
	}

	// Write header.
	// Note that the fat binary header is big-endian, regardless of the
	// endianness of the contained files.
	if err := binary.Write(out, binary.BigEndian, hdr); err != nil {
		return fmt.Errorf("failed to write to file: %w", err)
	}
	offset = int64(4 * len(hdr))

	// Write each contained file.
	for _, i := range inputs {
		if offset < i.offset {
			if _, err := out.Write(make([]byte, i.offset-offset)); err != nil {
				return fmt.Errorf("failed to write to file: %w", err)
			}
			offset = i.offset
		}
		if _, err := out.Write(i.data); err != nil {
			return fmt.Errorf("failed to write to file: %w", err)
		}
		offset += int64(len(i.data))
	}

	if err := out.Close(); err != nil {

View on GitHub (pinned to f5edd73956)

Solutions

  1. Check free disk space in the dist/ directory location and on the CI runner; clean up old dist/ artifacts
  2. Re-run the release; transient I/O errors usually do not recur
  3. Exclude dist/ from antivirus/backup/indexing tools or move dist to a local fast disk
  4. Check container/volume size limits if running in Docker or with tmpfs

Example fix

// before (CI with tiny tmpfs)
rules: ... # dist on tmpfs fills up
// after
goreleaser release --clean # with dist on a persistent volume with >1GB free
Defensive patterns

Strategy: validation

Validate before calling

func ensureDiskSpace(dir string, minBytes uint64) error {
	var st syscall.Statfs_t
	if err := syscall.Statfs(dir, &st); err != nil {
		return err
	}
	if uint64(st.Bavail)*uint64(st.Bsize) < minBytes {
		return fmt.Errorf("insufficient disk space in %s", dir)
	}
	return nil
}
// call ensureDiskSpace(distDir, 1<<30) before running goreleaser

Prevention

When it happens

Trigger: Writing the fat header via binary.Write(out, binary.BigEndian, hdr) fails while creating a universal (darwin_all) binary — e.g. disk full, I/O error, or the output file handle becoming invalid after os.Create succeeded in makeUniversalBinary.

Common situations: Disk quota/full disk on CI runners; ephemeral filesystem corruption; out-of-memory pressure causing short writes; running goreleaser in a container with a read-only or size-limited /dist volume; antivirus or indexing software locking files in dist/ on Windows/macOS.

Related errors


AI-assisted analysis of goreleaser/goreleaser@f5edd73956 (2026-09-05). Data as JSON: /api/errors/033180d9ae05126d. Report an issue: GitHub.