pulumi/pulumi · error
could not write output file %s: %w
Error message
could not write output file %s: %w
What it means
After creating directories, the host writes each generated file with os.WriteFile(0o600); failure returns 'could not write output file <filename>: %w'. This means the directory exists but the file could not be written — typically permissions, the path being a directory, or disk errors.
Source
Thrown at sdk/go/pulumi-language-go/main.go:1543
return &pulumirpc.GeneratePackageResponse{
Diagnostics: rpcDiagnostics,
}, nil
}
files, err := codegen.GeneratePackage("pulumi-language-go", pkg, req.LocalDependencies)
if err != nil {
return nil, err
}
for filename, data := range files {
outPath := filepath.Join(req.Directory, filename)
err := os.MkdirAll(filepath.Dir(outPath), 0o700)
if err != nil {
return nil, fmt.Errorf("could not create output directory %s: %w", filepath.Dir(filename), err)
}
err = os.WriteFile(outPath, data, 0o600)
if err != nil {
return nil, fmt.Errorf("could not write output file %s: %w", filename, err)
}
}
return &pulumirpc.GeneratePackageResponse{
Diagnostics: rpcDiagnostics,
}, nil
}
func (host *goLanguageHost) Pack(ctx context.Context, req *pulumirpc.PackRequest) (*pulumirpc.PackResponse, error) {
// Go is very simple, there's nothing it can do to pack so it just copies the source to the target.
// First read the modfile in the package directory to decide the folder name.
data, err := os.ReadFile(filepath.Join(req.PackageDirectory, "go.mod"))
if err != nil {
return nil, fmt.Errorf("read go.mod: %w", err)
}
mod, err := modfile.Parse("go.mod", data, nil)
if err != nil {View on GitHub (pinned to 793f7b2e16)
Solutions
- Check whether the named path is a directory and remove/rename it, then regenerate
- Ensure write permission on the output directory (chmod/chown) or choose a new -o target
- Free disk space / check quota
- Clean the previously generated SDK directory before regenerating
Example fix
// before: stale directory blocks the file sdk/go/pulumi-provider/internal/ // after rm -rf sdk/go/pulumi-provider/internal/ # or move it aside, then regenerate
Defensive patterns
Strategy: validation
Validate before calling
probe := filepath.Join(outDir, ".write-test")
if err := os.WriteFile(probe, []byte("ok"), 0o600); err != nil {
return fmt.Errorf("cannot write into %s: %w", outDir, err)
}
_ = os.Remove(probe) Try / catch
if _, err := genPackage(ctx, req); err != nil {
if strings.Contains(err.Error(), "could not write output file") {
return cleanOutDirAndRegenerate() // rm stale collisions, check perms/space
}
return err
} Prevention
- Clean previously generated SDK output before regenerating
- Verify write access to the output directory before generation
- Check for name collisions between files and directories across generations
- Ensure adequate disk space/quota in the output location
When it happens
Trigger: os.WriteFile fails during GeneratePackage: target path exists as a directory, read-only filesystem, immutable file, or quota/disk-full.
Common situations: Previous generation left a directory where a file should go (name collision between generations); output dir owned by another user; editing files in an IDE with a lock; full disk in CI.
Related errors
- read overlay file %q: %w
- create main directory: %w
- could not write output program: %w
- write Pulumi.yaml: %w
- could not create output directory %s: %w
AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31).
Data as JSON: /api/errors/dd61c086c043030d.
Report an issue: GitHub.