{"record":{"id":"3124afb83ffa1938","repo":"pulumi/pulumi","slug":"could-not-create-output-directory-s-w","errorCode":null,"errorMessage":"could not create output directory %s: %w","messagePattern":"could not create output directory (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/go/pulumi-language-go/main.go","lineNumber":1538,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\trpcDiagnostics := plugin.HclDiagnosticsToRPCDiagnostics(diags)\n\tif diags.HasErrors() {\n\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\"))","sourceCodeStart":1520,"sourceCodeEnd":1556,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/go/pulumi-language-go/main.go#L1520-L1556","documentation":"When writing generated SDK files, the host creates each file's parent directory with os.MkdirAll(0o700); if that fails it returns 'could not create output directory <dir>: %w'. The message reports filepath.Dir(filename) (relative name) while the failure is on the joined path under req.Directory. Usually a permissions or existing-path-conflict problem.","triggerScenarios":"os.MkdirAll fails while generating a package: req.Directory not writable, a file exists where a directory is needed, or the path is invalid/too long.","commonSituations":"Generating SDKs into a read-only checkout or root-owned directory; a stale file named like a directory (e.g. `sdk/go/...` path occupied by a file); disk full; Windows path-length limits.","solutions":["Check permissions on the target directory (`ls -ld`, chmod/chown or pick a writable -o/--directory)","Remove or rename any file occupying the conflicting path, then regenerate","Verify free disk space and valid path length","Run the command as a user with write access to the output location"],"exampleFix":"// before\n$ pulumi package gen-sdk ... -o /usr/local/lib/sdk\nerror: could not create output directory sdk/go/...\n// after\n$ mkdir -p ~/sdks && pulumi package gen-sdk ... -o ~/sdks","handlingStrategy":"validation","validationCode":"if err := os.MkdirAll(outDir, 0o700); err != nil {\n    return fmt.Errorf(\"output directory %s not creatable: %w\", outDir, err)\n}","typeGuard":null,"tryCatchPattern":"if _, err := genPackage(ctx, req); err != nil {\n    if strings.Contains(err.Error(), \"could not create output directory\") {\n        return pickWritableDirAndRegenerate()\n    }\n    return err\n}","preventionTips":["Pre-create and permission-check the output directory before generation","Never generate into system-owned paths; use a user-writable -o directory","Remove stale files that collide with expected directory names","Monitor disk space in CI runners"],"tags":["filesystem","permissions","codegen"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}