{"record":{"id":"5173287e8fd59803","repo":"pulumi/pulumi","slug":"getting-the-working-directory-w-517328","errorCode":null,"errorMessage":"getting the working directory: %w","messagePattern":"getting the working directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/pulumi/project/newcmd/io.go","lineNumber":39,"sourceCode":"\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}\n\n// ErrorIfNotEmptyDirectory returns an error if path is not empty.\nfunc ErrorIfNotEmptyDirectory(path string) error {\n\tinfos, err := os.ReadDir(path)\n\tif err != nil {\n\t\treturn err\n\t}","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/pkg/cmd/pulumi/project/newcmd/io.go#L21-L57","documentation":"Immediately after chdir, `UseSpecifiedDir` calls os.Getwd to confirm and return the new working directory. This error wraps a rare Getwd failure.","triggerScenarios":"`pulumi new --dir <path>` where os.Getwd fails after a successful chdir: the current directory was deleted concurrently, the resolved path exceeds path length limits, or restricted environments where getcwd(2) fails.","commonSituations":"Exotic filesystems/containers where getcwd fails; path longer than PATH_MAX; directory removed by another process mid-run. Very rare in practice.","solutions":["Re-run the command — usually transient","Shorten the --dir path (reduce nesting) to stay under PATH_MAX","Verify the directory still exists and the filesystem is healthy","Report a bug with OS details if reproducible"],"exampleFix":"// before\n$ pulumi new typescript --dir /very/deep/<200+ chars>...\ngetting the working directory: getcwd: ...\n// after\n$ pulumi new typescript --dir ~/proj","handlingStrategy":"retry","validationCode":"p=$(realpath -m \"$dir\"); [ ${#p} -lt 200 ] && echo ok || echo \"path too long\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep --dir paths short to stay under PATH_MAX","Avoid deleting directories while commands run","Re-run if getcwd fails transiently"],"tags":["cli","filesystem","getcwd"],"backgroundTag":"getcwd-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}