{"record":{"id":"620585dd7a5c5351","repo":"pulumi/pulumi","slug":"getting-selected-stack-w","errorCode":null,"errorMessage":"getting selected stack: %w","messagePattern":"getting selected stack: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/pulumi/stack/io.go","lineNumber":324,"sourceCode":"\t\tstackRef, parseErr := b.ParseStackReference(stackName)\n\t\tif parseErr != nil {\n\t\t\treturn nil, parseErr\n\t\t}\n\n\t\treturn CreateStack(ctx, sink, ws, b, stackRef, root, CreateStackOptions{\n\t\t\tSetCurrent: lopt.SetCurrent(), ConfigFile: configFile,\n\t\t})\n\t}\n\n\t// With the stack name selected, look it up from the backend.\n\tstackRef, err := b.ParseStackReference(option)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"parsing selected stack: %w\", err)\n\t}\n\t// GetStack may return (nil, nil) if the stack isn't found.\n\tstack, err := b.GetStack(ctx, stackRef)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getting selected stack: %w\", err)\n\t}\n\tif stack == nil {\n\t\treturn nil, backenderr.StackNotFoundError{StackName: stackRef.String()}\n\t}\n\n\t// If setCurrent is true, we'll persist this choice so it'll be used for future CLI operations.\n\tif lopt.SetCurrent() {\n\t\tif err = state.SetCurrentStack(ws, state.BackendURLKey(b), stackRef.FullyQualifiedName().String()); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\treturn stack, nil\n}\n\n// CreateStackOptions are the options for creating a stack from the CLI.\ntype CreateStackOptions struct {\n\t// Teams to grant access to the new stack.","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/pkg/cmd/pulumi/stack/io.go#L306-L342","documentation":"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).","triggerScenarios":"GetStack on the just-parsed stackRef fails — expired token, cloud API outage, or a backend returning an unexpected error for that stack identifier.","commonSituations":"Transient network failure right after selection, API rate limiting, stale login session, or permissions that make GetStack fail rather than return not-found.","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"],"exampleFix":"// before\n$ pulumi stack select prod\nerror: getting selected stack: 401 unauthorized\n// after\n$ pulumi login\n$ pulumi stack select prod","handlingStrategy":"retry","validationCode":"// pre-flight credential check\nif err := exec.Command(\"pulumi\", \"whoami\").Run(); err != nil {\n    return errors.New(\"refresh login before selecting a stack\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"getting selected stack\") {\n    // wrapped cause may be transient; retry with backoff\n    time.Sleep(2 * time.Second)\n    return getStackWithRetry(ctx, ref, 3)\n}","preventionTips":["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"],"tags":["cli","backend","network","authentication"],"backgroundTag":"backend-get-stack-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}