goreleaser/goreleaser · error

failed to write %s: %w

Error message

failed to write %s: %w

What it means

This error is returned by the aur_sources pipe's doRun when it cannot create the dist/aur output directory for an AUR source package file. It wraps the underlying os.MkdirAll error with the kind of file being written (e.g. PKGSRC/other info.kind), so you always see which artifact stage failed.

Source

Thrown at internal/pipe/aursources/aursources.go:160

			tpl:  aurTemplateData,
			ext:  ".pkgbuild",
			kind: artifact.SourcePkgBuild,
		},
		{
			name: ".SRCINFO",
			tpl:  srcInfoTemplate,
			ext:  ".srcinfo",
			kind: artifact.SourceSrcInfo,
		},
	} {
		pkgContent, err := buildPkgFile(ctx, aur, cl, archives, info.tpl)
		if err != nil {
			return err
		}

		path := filepath.Join(ctx.Config.Dist, "aur", aur.Name+info.ext)
		if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
			return fmt.Errorf("failed to write %s: %w", info.kind, err)
		}
		log.WithField("file", path).Info("writing")
		if err := os.WriteFile(path, []byte(pkgContent), 0o644); err != nil { //nolint:gosec
			return fmt.Errorf("failed to write %s: %w", info.kind, err)
		}

		ctx.Artifacts.Add(&artifact.Artifact{
			Name: info.name,
			Path: path,
			Type: info.kind,
			Extra: map[string]any{
				aurExtra:         aur,
				artifact.ExtraID: aur.Name,
			},
		})
	}

	return nil

View on GitHub (pinned to f5edd73956)

Solutions

  1. Fix permissions on the dist directory (chown/chmod) so the goreleaser user can create directories
  2. Remove or rename any file named 'aur' inside dist, or run goreleaser with a clean dist (rm -rf dist)
  3. Set a writable dist path in .goreleaser.yaml (dist: /tmp/dist) or via --dist flag
  4. Check disk space (df -h) and free up space

Example fix

// before
dist: ./output/aur   # read-only in CI
// after
dist: ./dist         # writable by the running user
Defensive patterns

Strategy: validation

Validate before calling

dist := "dist" // ctx.Config.Dist
aurDir := filepath.Join(dist, "aur")
if fi, err := os.Stat(aurDir); err == nil && !fi.IsDir() {
	return fmt.Errorf("%s exists and is not a directory", aurDir)
}
if err := os.MkdirAll(aurDir, 0o755); err != nil {
	return err
}

Prevention

When it happens

Trigger: os.MkdirAll(filepath.Join(ctx.Config.Dist, "aur")) fails: dist path points to a read-only location, a non-directory file named 'aur' exists in dist, the disk is full, or a permission error occurs on the dist directory.

Common situations: Running goreleaser with a --dist flag or dist: config pointing somewhere the CI user cannot write; a corrupted dist directory where a file named 'aur' exists; Docker containers with read-only mounts.

Related errors


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