{"record":{"id":"4cae879b442c6d2e","repo":"pulumi/pulumi","slug":"failed-to-create-directory-for-sdk-w","errorCode":null,"errorMessage":"failed to create directory for SDK: %w","messagePattern":"failed to create directory for SDK: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/pulumi/packages/packages.go","lineNumber":129,"sourceCode":"\tdiags, err := GenSDK(\n\t\tpctx.Request(),\n\t\tregistry,\n\t\tlanguage,\n\t\ttempOut,\n\t\tpkg,\n\t\t\"\",    /*overlays*/\n\t\tlocal, /*local*/\n\t)\n\tif err != nil {\n\t\treturn nil, nil, diags, fmt.Errorf(\"failed to generate SDK: %w\", err)\n\t}\n\n\tout := filepath.Join(root, \"sdks\")\n\tfmt.Fprintf(stdout, \"Successfully generated an SDK for the %s package at %s\\n\", pkg.Name, out)\n\n\terr = os.MkdirAll(out, 0o755)\n\tif err != nil {\n\t\treturn nil, nil, diags, fmt.Errorf(\"failed to create directory for SDK: %w\", err)\n\t}\n\n\toutName := pkg.Name\n\tif pkg.Namespace != \"\" {\n\t\toutName = pkg.Namespace + \"-\" + outName\n\t}\n\tout = filepath.Join(out, outName)\n\n\t// If directory already exists, remove it completely before copying new files\n\tif _, err := os.Stat(out); err == nil {\n\t\tif err := os.RemoveAll(out); err != nil {\n\t\t\treturn nil, nil, diags, fmt.Errorf(\"failed to clean existing SDK directory: %w\", err)\n\t\t}\n\t}\n\n\terr = fsutil.CopyFile(out, filepath.Join(tempOut, language), nil)\n\tif err != nil {\n\t\treturn nil, nil, diags, fmt.Errorf(\"failed to move SDK to project: %w\", err)","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/pkg/cmd/pulumi/packages/packages.go#L111-L147","documentation":"When `pulumi package add`/`gen-sdk` generates a language SDK, it first creates the destination directory `<project>/sdks` with os.MkdirAll. If the OS cannot create that directory tree, the command wraps the OS error with this message and returns it alongside any diagnostics. It is a filesystem/permission failure, not a schema or codegen problem.","triggerScenarios":"os.MkdirAll(filepath.Join(root, \"sdks\"), 0o755) returns an error: e.g. the project root is read-only, a parent path component is missing or is a file, the disk is full, or the process lacks write permission on the project directory.","commonSituations":"Running the CLI in a project owned by another user, running inside a container with a read-only mounted volume, project path is actually a file, or a read-only network mount; also on Windows when an antivirus briefly locks the path.","solutions":["Check write permissions on the project root: `ls -ld .` and fix with chmod/chown or move the project.","Verify no file named `sdks` exists where a directory is needed (`rm` or rename it).","Check available disk space with `df -h` and free space if full.","If in a container, ensure the volume is mounted read-write (`docker run -v dir:/work` without :ro)."],"exampleFix":"// before (shell)\npulumi package add ../my-provider\n// error: failed to create directory for SDK: mkdir .: read-only file system\n// after (shell)\nchmod u+w . && pulumi package add ../my-provider","handlingStrategy":"validation","validationCode":"// shell pre-check before running the CLI\nif [ ! -w . ]; then echo \"project dir not writable\"; exit 1; fi\n[ ! -e sdks ] || [ -d sdks ] || { echo \"sdks exists but is a file\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure the project directory is writable by the invoking user before codegen.","Never mount project volumes read-only when running `pulumi package add`.","Avoid creating a file named `sdks` in project root."],"tags":["filesystem","permissions","cli","sdk-generation"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}