pulumi/pulumi · error

getting the working directory: %w

Error message

getting the working directory: %w

What it means

Immediately after chdir, `UseSpecifiedDir` calls os.Getwd to confirm and return the new working directory. This error wraps a rare Getwd failure.

Source

Thrown at pkg/cmd/pulumi/project/newcmd/io.go:39

// 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": {},
}

// ErrorIfNotEmptyDirectory returns an error if path is not empty.
func ErrorIfNotEmptyDirectory(path string) error {
	infos, err := os.ReadDir(path)
	if err != nil {
		return err
	}

View on GitHub (pinned to 793f7b2e16)

Solutions

  1. Re-run the command — usually transient
  2. Shorten the --dir path (reduce nesting) to stay under PATH_MAX
  3. Verify the directory still exists and the filesystem is healthy
  4. Report a bug with OS details if reproducible

Example fix

// before
$ pulumi new typescript --dir /very/deep/<200+ chars>...
getting the working directory: getcwd: ...
// after
$ pulumi new typescript --dir ~/proj
Defensive patterns

Strategy: retry

Validate before calling

p=$(realpath -m "$dir"); [ ${#p} -lt 200 ] && echo ok || echo "path too long"

Prevention

When it happens

Trigger: `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.

Common situations: Exotic filesystems/containers where getcwd fails; path longer than PATH_MAX; directory removed by another process mid-run. Very rare in practice.

Related errors


AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31). Data as JSON: /api/errors/5173287e8fd59803. Report an issue: GitHub.