pulumi/pulumi · error
getting selected stack: %w
Error message
getting selected stack: %w
What it means
After the stack reference parses successfully, the CLI calls backend.GetStack to fetch the stack metadata; this error wraps any backend error from that call. It means the backend itself failed (network/auth/API), distinct from a stack simply not existing (which yields StackNotFoundError).
Source
Thrown at pkg/cmd/pulumi/stack/io.go:324
stackRef, parseErr := b.ParseStackReference(stackName)
if parseErr != nil {
return nil, parseErr
}
return CreateStack(ctx, sink, ws, b, stackRef, root, CreateStackOptions{
SetCurrent: lopt.SetCurrent(), ConfigFile: configFile,
})
}
// With the stack name selected, look it up from the backend.
stackRef, err := b.ParseStackReference(option)
if err != nil {
return nil, fmt.Errorf("parsing selected stack: %w", err)
}
// GetStack may return (nil, nil) if the stack isn't found.
stack, err := b.GetStack(ctx, stackRef)
if err != nil {
return nil, fmt.Errorf("getting selected stack: %w", err)
}
if stack == nil {
return nil, backenderr.StackNotFoundError{StackName: stackRef.String()}
}
// If setCurrent is true, we'll persist this choice so it'll be used for future CLI operations.
if lopt.SetCurrent() {
if err = state.SetCurrentStack(ws, state.BackendURLKey(b), stackRef.FullyQualifiedName().String()); err != nil {
return nil, err
}
}
return stack, nil
}
// CreateStackOptions are the options for creating a stack from the CLI.
type CreateStackOptions struct {
// Teams to grant access to the new stack.View on GitHub (pinned to 793f7b2e16)
Solutions
- Retry the command — transient API/network errors often resolve
- Re-login (`pulumi login`) to refresh credentials
- Inspect the wrapped cause with verbose output; address 401/403/5xx accordingly
- Verify the backend service status if errors persist
Example fix
// before $ pulumi stack select prod error: getting selected stack: 401 unauthorized // after $ pulumi login $ pulumi stack select prod
Defensive patterns
Strategy: retry
Validate before calling
// pre-flight credential check
if err := exec.Command("pulumi", "whoami").Run(); err != nil {
return errors.New("refresh login before selecting a stack")
} Try / catch
if err != nil && strings.Contains(err.Error(), "getting selected stack") {
// wrapped cause may be transient; retry with backoff
time.Sleep(2 * time.Second)
return getStackWithRetry(ctx, ref, 3)
} Prevention
- Re-login before long CI jobs that fetch stack metadata
- Handle 429 rate limits with exponential backoff
- Monitor backend service status for self-hosted deployments
When it happens
Trigger: GetStack on the just-parsed stackRef fails — expired token, cloud API outage, or a backend returning an unexpected error for that stack identifier.
Common situations: Transient network failure right after selection, API rate limiting, stale login session, or permissions that make GetStack fail rather than return not-found.
Related errors
- could not query backend for stacks: %w
- resolving default org: %w
- could not get Private Registry backend: %w
- getting latest configuration: %w
- getting deployment: %w
AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31).
Data as JSON: /api/errors/620585dd7a5c5351.
Report an issue: GitHub.