{"record":{"id":"fd15ae382cdebd5c","repo":"pulumi/pulumi","slug":"getting-stack-policy-packs-w","errorCode":null,"errorMessage":"getting stack policy packs: %w","messagePattern":"getting stack policy packs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/pulumi/policy/policy_install.go","lineNumber":119,"sourceCode":"\t\t\treturn cmdStack.RequireStack(ctx, cmd.diag, pkgWorkspace.Instance,\n\t\t\t\tcmdBackend.DefaultLoginManager, stackName, cmdStack.LoadOnly, displayOpts, \"\")\n\t\t}\n\t}\n\n\t// Get the stack (uses current stack if stackName is empty).\n\ts, err := cmd.requireStack(ctx, stackName)\n\tif err != nil {\n\t\tif stackName == \"\" && errors.Is(err, workspace.ErrProjectNotFound) {\n\t\t\treturn errors.New(\"could not find a Pulumi project in the current working directory; \" +\n\t\t\t\t\"please specify a stack using the --stack flag.\")\n\t\t}\n\t\treturn err\n\t}\n\n\t// Fetch the required policy packs for the stack.\n\tpolicyPacks, err := s.Backend().GetStackPolicyPacks(ctx, s.Ref())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting stack policy packs: %w\", err)\n\t}\n\n\tif len(policyPacks) == 0 {\n\t\tfmt.Fprintf(cmd.stderr, \"No policy packs to install for stack %s\\n\", s.Ref().String())\n\t\treturn nil\n\t}\n\n\tcwd, err := cmd.getwd()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting current working directory: %w\", err)\n\t}\n\n\treg := cmdCmd.NewDefaultRegistry(\n\t\tctx, cmdBackend.DefaultLoginManager, pkgWorkspace.Instance, nil, cmd.diag, env.Global())\n\tpluginHost, err := pkghost.New(context.WithoutCancel(ctx), cmd.diag, cmd.diag, nil,\n\t\tpkgWorkspace.EnsureLanguageInstalled, schema.NewLoaderServerFromContext, convert.NewMapperServerFromContext,\n\t\tpackageworkspace.NewResolverServer(reg))\n\tif err != nil {","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/pkg/cmd/pulumi/policy/policy_install.go#L101-L137","documentation":"This error wraps the failure of Backend().GetStackPolicyPacks(ctx, s.Ref()) while `pulumi policy install` fetches the policy packs configured for the stack from the backend. The underlying error (auth, network, API, or stack-not-found) is preserved via %w. It means the CLI could not even enumerate the stack's required packs, so nothing was installed.","triggerScenarios":"Running `pulumi policy install` when the stack ref is wrong or missing server-side, the Pulumi Cloud API is unreachable, the auth token is expired/invalid, or the backend returns a non-200 for the stack-policy-packs endpoint.","commonSituations":"Expired Pulumi access token after `pulumi login` session aged out; VPN/firewall blocking api.pulumi.com; typo'd --stack value pointing at a nonexistent stack; self-hosted backend without the policy API implemented.","solutions":["Run `pulumi whoami` / `pulumi stack` to verify auth and that the stack ref resolves before retrying","Re-login with `pulumi login` to refresh an expired token","Check network/VPN connectivity to api.pulumi.com (curl the API URL)","Verify the --stack argument points to an existing stack in the current backend"],"exampleFix":"// before\npulumi policy install --stack myorg/prod/wrong-name\n// after\npulumi stack select myorg/prod  # confirm the stack exists first\npulumi policy install","handlingStrategy":"retry","validationCode":"if !strings.Contains(out, backend) && exec.Command(\"pulumi\",\"whoami\").Run() != nil { return fmt.Errorf(\"not logged in; run pulumi login\") }","typeGuard":null,"tryCatchPattern":"err := runCmd(\"pulumi\", \"policy\", \"install\")\nif err != nil {\n    if strings.Contains(err.Error(), \"getting stack policy packs\") {\n        // check auth/connectivity, then retry with backoff\n    }\n}","preventionTips":["Run `pulumi whoami` before automation to verify auth","Use `pulumi stack select` instead of hand-typed stack refs","Monitor token expiry in CI and re-login via service account tokens"],"tags":["cli","policy-packs","backend","api"],"backgroundTag":"pulumi-backend-request-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}