pulumi/pulumi · error

getting current working directory: %w

Error message

getting current working directory: %w

What it means

ResolveContext resolves the Pulumi Cloud context for `pulumi api` commands, starting by reading the current working directory via os.Getwd. If the OS cannot determine the working directory (e.g. it was deleted or is unreadable), the error is wrapped as 'getting current working directory' and resolution aborts before any project or credential lookup.

Source

Thrown at pkg/cmd/pulumi/cloud/resolve.go:70

	StackProj string
	StackName string
	LoggedIn  bool
}

// ResolveContext returns the Pulumi Cloud context for a `pulumi api`
// invocation. The resolved OrgName comes from pkgBackend.GetDefaultOrg
// (which prefers a locally-configured default and falls back to the
// backend's opinion) so {orgName} template vars resolve sensibly even
// outside a project directory.
//
// Credential lookup is non-interactive: when no credentials are stored,
// ResolveContext returns an anonymous Client + the resolved CloudURL with
// LoggedIn=false rather than prompting or failing. Callers that require
// authentication should check LoggedIn and surface their own error.
func ResolveContext(ctx context.Context) (*ResolvedContext, error) {
	cwd, err := os.Getwd()
	if err != nil {
		return nil, fmt.Errorf("getting current working directory: %w", err)
	}

	ws := pkgWorkspace.Instance
	project, _, err := ws.ReadProject(cwd)
	if err != nil && !errors.Is(err, workspace.ErrProjectNotFound) {
		return nil, fmt.Errorf("reading project: %w", err)
	}

	// Resolve the URL ourselves before probing credentials so we honour
	// a project-declared backend (Pulumi.yaml's `backend.url`) without
	// triggering CurrentBackend's interactive login path.
	var projectURL string
	if project != nil {
		if u, perr := pkgWorkspace.GetCurrentCloudURL(ws, env.Global(), project); perr == nil {
			projectURL = u
		}
	}
	cloudURL := httpstate.ValueOrDefaultURL(ws, projectURL)

View on GitHub (pinned to 793f7b2e16)

Solutions

  1. cd to a directory that exists (e.g. cd ~ or cd to your project) and re-run the command
  2. If in a deleted-directory shell, open a new shell or `cd $(pwd)` after the directory is recreated
  3. In scripts/CI, ensure the working directory exists before invoking pulumi commands

Example fix

// before (shell in a deleted dir)
pulumi api list

// after
projectdir=/path/to/project
cd "$projectdir" || exit 1
pulumi api list
Defensive patterns

Strategy: validation

Validate before calling

if wd, err := os.Getwd(); err != nil {
	fmt.Fprintf(os.Stderr, "working directory unavailable: %v\n", err)
	os.Exit(1)
}

Prevention

When it happens

Trigger: os.Getwd fails — typically because the process's current directory no longer exists (deleted while the shell is inside it), the inode is stale after a mount/removal, or a permissions/environment issue prevents path resolution.

Common situations: Running `pulumi api` in a shell whose cwd was deleted (e.g. `rm -rf` of the directory in another terminal, or a CI workspace cleaned up mid-run); running inside a container with a removed workdir; running from a directory on an unmounted volume.

Related errors


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