{"record":{"id":"b2d0cf76760cfff5","repo":"pulumi/pulumi","slug":"failed-to-cancel-update-w","errorCode":null,"errorMessage":"failed to cancel update: %w","messagePattern":"failed to cancel update: %w","errorType":"exception","errorClass":"AutoError","httpStatus":null,"severity":"error","filePath":"sdk/go/auto/stack.go","lineNumber":1355,"sourceCode":"// Note that this operation is _very dangerous_, and may leave the stack in an inconsistent state\n// if a resource operation was pending when the update was canceled.\nfunc (s *Stack) Cancel(ctx context.Context) error {\n\tbo := s.cliBaseOptions()\n\tstack := s.Name()\n\tapi, ok := s.cliAPI()\n\tif !ok {\n\t\treturn errors.New(\"Stack.Cancel requires a *LocalWorkspace; the workspace does not expose a generated CLI API\")\n\t}\n\tresult, err := api.Cancel(ctx, nil, func(o *optcancel.Options) {\n\t\to.Cwd = bo.Cwd\n\t\to.AdditionalEnv = bo.AdditionalEnv\n\t\to.Stdout = bo.Stdout\n\t\to.Stderr = bo.Stderr\n\t\to.Stdin = bo.Stdin\n\t\to.Stack = stack\n\t})\n\tif err != nil {\n\t\treturn newAutoError(fmt.Errorf(\"failed to cancel update: %w\", err),\n\t\t\tresult.Stdout, result.Stderr, result.ExitCode)\n\t}\n\tif cbErr := s.Workspace().PostCommandCallback(ctx, stack); cbErr != nil {\n\t\treturn fmt.Errorf(\"command ran successfully, but error running PostCommandCallback: %w\", cbErr)\n\t}\n\treturn nil\n}\n\n// cliAPI returns the workspace's auto-generated CLI API. The second\n// return is false when the workspace is not a *LocalWorkspace.\nfunc (s *Stack) cliAPI() (*automation.API, bool) {\n\tlws, ok := s.workspace.(*LocalWorkspace)\n\tif !ok || lws == nil {\n\t\treturn nil, false\n\t}\n\treturn lws.cliAPI, lws.cliAPI != nil\n}\n","sourceCodeStart":1337,"sourceCodeEnd":1373,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/go/auto/stack.go#L1337-L1373","documentation":"This error is returned by Stack.Cancel when the underlying `pulumi cancel` command fails to terminate a running update. It is wrapped in an AutoError carrying the command's stdout, stderr, and exit code so callers can inspect the CLI failure. The %w preserves the original exec error for errors.Is/As checks.","triggerScenarios":"Calling stack.Cancel(ctx) when the workspace cannot locate the Stack, the Pulumi CLI binary is missing or mis-versioned, or the `pulumi stack cancel --yes` subprocess exits non-zero.","commonSituations":"Stale PULUMI_ACCESS_TOKEN, the stack was already canceled/completed, offline with Pulumi Cloud backend, or a broken PATH where the pulumi binary cannot be executed.","solutions":["Inspect the AutoError's Stdout/Stderr/ExitCode fields to see the CLI's cancellation failure reason","Verify the pulumi CLI is on PATH and its version is supported by the automation API","Check the stack actually has a running update (`pulumi stack history`) before canceling","Re-authenticate (pulumi login) if the backend rejected the request"],"exampleFix":"// before\nif err := stack.Cancel(ctx); err != nil { log.Fatal(err) }\n// after\nvar autoErr *auto.AutoError\nif err := stack.Cancel(ctx); err != nil {\n    if errors.As(err, &autoErr) {\n        log.Printf(\"cancel failed: exit=%d stdout=%s stderr=%s\", autoErr.ExitCode, autoErr.Stdout, autoErr.Stderr)\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"if _, err := exec.LookPath(\"pulumi\"); err != nil { return fmt.Errorf(\"pulumi CLI not found: %w\", err) }","typeGuard":"var ae *auto.AutoError\nif errors.As(err, &ae) { /* inspect ae.Stdout, ae.Stderr, ae.ExitCode */ }","tryCatchPattern":"err := stack.Cancel(ctx)\nvar ae *auto.AutoError\nif errors.As(err, &ae) {\n    log.Printf(\"cancel failed exit=%d: %s\", ae.ExitCode, ae.Stderr)\n}\nreturn err","preventionTips":["Verify the pulumi CLI is installed and on PATH before operations","Confirm a run is actually in progress before canceling","Keep CLI authenticated with pulumi login before calling Cancel"],"tags":["go","automation-api","cli","cancel"],"backgroundTag":"cli-command-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}