{"record":{"id":"80f97230a9392a4f","repo":"spinnaker/spinnaker","slug":"encountered-an-error-canceling-execution-with-id","errorCode":null,"errorMessage":"encountered an error canceling execution with id %s, status code: %d\n","messagePattern":"encountered an error canceling execution with id (.+?), status code: (.+?)\n","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"spin/cmd/pipeline/execution/cancel.go","lineNumber":65,"sourceCode":"\t}\n\n\treturn cmd\n}\n\nfunc cancelExecution(cmd *cobra.Command, options *cancelOptions, args []string) error {\n\texecutionId, err := util.ReadArgsOrStdin(args)\n\tif executionId == \"\" {\n\t\treturn errors.New(\"no execution id supplied, exiting\")\n\t}\n\n\tresp, err := options.GateClient.PipelineControllerAPI.CancelPipeline(options.GateClient.Context,\n\t\texecutionId).Execute()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"encountered an error canceling execution with id %s, status code: %d\\n\",\n\t\t\texecutionId,\n\t\t\tresp.StatusCode)\n\t}\n\n\toptions.Ui.Success(fmt.Sprintf(\"Execution %s successfully canceled\", executionId))\n\treturn nil\n}\n","sourceCodeStart":47,"sourceCodeEnd":73,"githubUrl":"https://github.com/spinnaker/spinnaker/blob/1d4a5d0f6d10d0232b1af077decd559b68a94a5e/spin/cmd/pipeline/execution/cancel.go#L47-L73","documentation":"After CancelPipeline returns successfully at the transport level, the CLI expects HTTP 200 OK. Any other status produces this error naming the execution id and status code. It indicates the cancel request was rejected or failed server-side and the execution may still be running.","triggerScenarios":"`spin pipeline execution cancel <id>` where CancelPipeline.Execute() succeeds but resp.StatusCode != 200: execution id does not exist (404), execution already finished (409/400 depending on Gate version), or RBAC denial (403).","commonSituations":"Trying to cancel an execution that already completed; stale id from a cached/old list; user lacking write permission on the application; Gate restarted and lost the execution reference.","solutions":["Confirm the execution is still running: `spin pipeline execution get <id>`","If 404, the id is wrong or the execution record was deleted; fetch a fresh id via `spin pipeline execution list --pipeline-id <id>`","If 403, request cancel permission on the application in Fiat/RBAC","Check Gate logs for the cancel request's error detail"],"exampleFix":"// before: assumes cancel always works\nspin pipeline execution cancel \"$ID\"\n// after: verify the execution is still running first\nSTATUS=$(spin pipeline execution get \"$ID\" | jq -r '.status')\ncase \"$STATUS\" in\n  RUNNING|NOT_STARTED|PAUSED) spin pipeline execution cancel \"$ID\" ;;\n  *) echo \"execution $ID is $STATUS; nothing to cancel\" ;;\nesac","handlingStrategy":"try-catch","validationCode":"// Verify the execution is still cancelable first\nspin pipeline execution get \"$ID\" | jq -e '.status | test(\"RUNNING|NOT_STARTED|PAUSED\")' || { echo \"not cancelable\"; exit 1; }","typeGuard":"func isCancelable(status string) bool {\n    switch status { case \"RUNNING\", \"NOT_STARTED\", \"PAUSED\": return true }\n    return false\n}","tryCatchPattern":"if resp.StatusCode != http.StatusOK {\n    if resp.StatusCode == http.StatusNotFound {\n        return fmt.Errorf(\"execution %s not found (already finished or purged)\", id)\n    }\n    return fmt.Errorf(\"cancel failed with status %d\", resp.StatusCode)\n}","preventionTips":["Fetch fresh execution ids before canceling; don't reuse cached ones","Check execution status before canceling","Ensure the service account has write access to the application","Treat 404 as 'already finished' in retry logic"],"tags":["cli","http","status-code","gate-api"],"backgroundTag":"http-non-200-response","analyzedSha":"1d4a5d0f6d10d0232b1af077decd559b68a94a5e","analyzedAt":"2026-09-10T14:13:07.222Z","contentChangedAt":"2026-09-10T14:13:07.222Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}