pulumi/pulumi · error
changing the working directory: %w
Error message
changing the working directory: %w
What it means
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.
Source
Thrown at pkg/cmd/pulumi/project/newcmd/io.go:32
package newcmd
import (
"fmt"
"os"
)
// Ensure the directory exists and uses it as the current working
// directory.
func UseSpecifiedDir(dir string) (string, error) {
// Ensure the directory exists.
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return "", fmt.Errorf("creating the directory: %w", err)
}
// Change the working directory to the specified directory.
if err := os.Chdir(dir); err != nil {
return "", fmt.Errorf("changing the working directory: %w", err)
}
// Get the new working directory.
var cwd string
var err error
if cwd, err = os.Getwd(); err != nil {
return "", fmt.Errorf("getting the working directory: %w", err)
}
return cwd, nil
}
// File or directory names that are considered invisible
// when considering whether a directory is empty.
var invisibleDirEntries = map[string]struct{}{
".git": {},
".hg": {},
".bzr": {},
}View on GitHub (pinned to 793f7b2e16)
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
Example fix
// before $ pulumi new go --dir /proc/self/x changing the working directory: chdir /proc/self/x: ... // after $ pulumi new go --dir ./myproject
Defensive patterns
Strategy: validation
Validate before calling
import os
p = os.path.abspath(target_dir)
assert os.path.isdir(p), f"{p} is not a directory"
assert os.access(p, os.X_OK), f"no traverse permission on {p}" Prevention
- Verify execute permission on every path component
- Avoid symlink loops and exotic filesystems for --dir
- Use simple local paths for scaffolding
When it happens
Trigger: `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).
Common situations: Deeply nested --dir paths where an intermediate directory lacks execute permission; NFS/network filesystems with flaky behavior; concurrent processes deleting the directory.
Related errors
- getting current working directory: %w
- error starting pulumi-watch: %w
- Could not locate an executable pulumi-watch, found %v withou
- writing temporary file: %w
- reading temporary file: %w
AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31).
Data as JSON: /api/errors/fa560973b6b7e090.
Report an issue: GitHub.