{"record":{"id":"fa560973b6b7e090","repo":"pulumi/pulumi","slug":"changing-the-working-directory-w-fa5609","errorCode":null,"errorMessage":"changing the working directory: %w","messagePattern":"changing the working directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/pulumi/project/newcmd/io.go","lineNumber":32,"sourceCode":"\npackage newcmd\n\nimport (\n\t\"fmt\"\n\t\"os\"\n)\n\n// Ensure the directory exists and uses it as the current working\n// directory.\nfunc UseSpecifiedDir(dir string) (string, error) {\n\t// Ensure the directory exists.\n\tif err := os.MkdirAll(dir, os.ModePerm); err != nil {\n\t\treturn \"\", fmt.Errorf(\"creating the directory: %w\", err)\n\t}\n\n\t// Change the working directory to the specified directory.\n\tif err := os.Chdir(dir); err != nil {\n\t\treturn \"\", fmt.Errorf(\"changing the working directory: %w\", err)\n\t}\n\n\t// Get the new working directory.\n\tvar cwd string\n\tvar err error\n\tif cwd, err = os.Getwd(); err != nil {\n\t\treturn \"\", fmt.Errorf(\"getting the working directory: %w\", err)\n\t}\n\treturn cwd, nil\n}\n\n// File or directory names that are considered invisible\n// when considering whether a directory is empty.\nvar invisibleDirEntries = map[string]struct{}{\n\t\".git\": {},\n\t\".hg\":  {},\n\t\".bzr\": {},\n}","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/pkg/cmd/pulumi/project/newcmd/io.go#L14-L50","documentation":"After creating and entering the `--dir` target, `UseSpecifiedDir` calls os.Chdir. This error wraps a chdir failure — the directory could not be made the process working directory.","triggerScenarios":"`pulumi new <template> --dir <path>` where os.Chdir fails: the directory was removed between creation and chdir (race), traversal permission denied on a parent, or dir resolves to something not enterable (e.g. a symlink loop).","commonSituations":"Deeply nested --dir paths where an intermediate directory lacks execute permission; NFS/network filesystems with flaky behavior; concurrent processes deleting the directory.","solutions":["Check execute (traverse) permission on every component of the --dir path","Verify the path is a real directory and not a symlink loop","Re-run the command; if a race, ensure no other process is removing the directory","Use a simpler local path for --dir"],"exampleFix":"// before\n$ pulumi new go --dir /proc/self/x\nchanging the working directory: chdir /proc/self/x: ...\n// after\n$ pulumi new go --dir ./myproject","handlingStrategy":"validation","validationCode":"import os\np = os.path.abspath(target_dir)\nassert os.path.isdir(p), f\"{p} is not a directory\"\nassert os.access(p, os.X_OK), f\"no traverse permission on {p}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify execute permission on every path component","Avoid symlink loops and exotic filesystems for --dir","Use simple local paths for scaffolding"],"tags":["cli","filesystem","chdir"],"backgroundTag":"chdir-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}