{"record":{"id":"dd61c086c043030d","repo":"pulumi/pulumi","slug":"could-not-write-output-file-s-w","errorCode":null,"errorMessage":"could not write output file %s: %w","messagePattern":"could not write output file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/go/pulumi-language-go/main.go","lineNumber":1543,"sourceCode":"\t\treturn &pulumirpc.GeneratePackageResponse{\n\t\t\tDiagnostics: rpcDiagnostics,\n\t\t}, nil\n\t}\n\tfiles, err := codegen.GeneratePackage(\"pulumi-language-go\", pkg, req.LocalDependencies)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tfor filename, data := range files {\n\t\toutPath := filepath.Join(req.Directory, filename)\n\t\terr := os.MkdirAll(filepath.Dir(outPath), 0o700)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"could not create output directory %s: %w\", filepath.Dir(filename), err)\n\t\t}\n\n\t\terr = os.WriteFile(outPath, data, 0o600)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"could not write output file %s: %w\", filename, err)\n\t\t}\n\t}\n\n\treturn &pulumirpc.GeneratePackageResponse{\n\t\tDiagnostics: rpcDiagnostics,\n\t}, nil\n}\n\nfunc (host *goLanguageHost) Pack(ctx context.Context, req *pulumirpc.PackRequest) (*pulumirpc.PackResponse, error) {\n\t// Go is very simple, there's nothing it can do to pack so it just copies the source to the target.\n\n\t// First read the modfile in the package directory to decide the folder name.\n\tdata, err := os.ReadFile(filepath.Join(req.PackageDirectory, \"go.mod\"))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read go.mod: %w\", err)\n\t}\n\tmod, err := modfile.Parse(\"go.mod\", data, nil)\n\tif err != nil {","sourceCodeStart":1525,"sourceCodeEnd":1561,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/go/pulumi-language-go/main.go#L1525-L1561","documentation":"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.","triggerScenarios":"os.WriteFile fails during GeneratePackage: target path exists as a directory, read-only filesystem, immutable file, or quota/disk-full.","commonSituations":"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.","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"],"exampleFix":"// before: stale directory blocks the file\nsdk/go/pulumi-provider/internal/\n// after\nrm -rf sdk/go/pulumi-provider/internal/  # or move it aside, then regenerate","handlingStrategy":"validation","validationCode":"probe := filepath.Join(outDir, \".write-test\")\nif err := os.WriteFile(probe, []byte(\"ok\"), 0o600); err != nil {\n    return fmt.Errorf(\"cannot write into %s: %w\", outDir, err)\n}\n_ = os.Remove(probe)","typeGuard":null,"tryCatchPattern":"if _, err := genPackage(ctx, req); err != nil {\n    if strings.Contains(err.Error(), \"could not write output file\") {\n        return cleanOutDirAndRegenerate() // rm stale collisions, check perms/space\n    }\n    return err\n}","preventionTips":["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"],"tags":["filesystem","write","codegen"],"backgroundTag":"file-write-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}