{"record":{"id":"affd04569c90f26e","repo":"gitbutlerapp/gitbutler","slug":"failed-to-unstack-github-stack","errorCode":null,"errorMessage":"Failed to unstack GitHub stack: {}","messagePattern":"Failed to unstack GitHub stack: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-github/src/stacks.rs","lineNumber":353,"sourceCode":"            bail!(\n                \"Failed to add to GitHub stack: {}\",\n                response_error(response).await\n            );\n        }\n        Ok(())\n    }\n\n    async fn unstack(&self, owner: &str, repo: &str, stack_number: i64) -> Result<()> {\n        let response = self\n            .client\n            .post(format!(\n                \"{}/repos/{owner}/{repo}/stacks/{stack_number}/unstack\",\n                self.base_url\n            ))\n            .send()\n            .await?;\n        if !response.status().is_success() {\n            bail!(\n                \"Failed to unstack GitHub stack: {}\",\n                response_error(response).await\n            );\n        }\n        Ok(())\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    fn stack(number: i64, members: &[i64]) -> Stack {\n        Stack {\n            number,\n            pull_requests: members\n                .iter()\n                .map(|number| StackPullRequest {","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-github/src/stacks.rs#L335-L371","documentation":"The REST request to unstack (detach) a GitHub stack returned a non-success HTTP status; the response body is embedded via `response_error`. Unstacking removes the stack association for the given stack number.","triggerScenarios":"Calling unstack when POST/DELETE to `{base_url}/repos/{owner}/{repo}/stacks/{stack_number}/unstack` fails — 404 for a stack number that no longer exists, 401/403 for credential issues, 5xx for GitHub-side errors.","commonSituations":"The stack was already unstacked in another session or via the GitHub UI (404); token revocation; GHES instance lacking the endpoint.","solutions":["Inspect the embedded status/body for the exact reason.","If 404, treat the stack as already removed: re-list stacks and skip or reconcile state.","If 401/403, refresh the token and its repo access.","Retry with backoff on 5xx; check GitHub status for incidents."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"let stacks = stacks_client.existing_stacks(owner, repo, pr).await?;\nanyhow::ensure!(stacks.iter().any(|s| s.number == stack_number), \"stack {stack_number} already gone\");","typeGuard":null,"tryCatchPattern":"match stacks.unstack(owner, repo, stack_number).await {\n    Ok(()) => (),\n    Err(e) if e.to_string().contains(\"404\") => (), // already unstacked — idempotent success\n    Err(e) => return Err(e),\n}","preventionTips":["Treat 404 on unstack as success (idempotency).","Avoid caching stack numbers across sessions.","Refresh credentials before batch stack mutations.","Retry 5xx with backoff."],"tags":["github","api","http","stacks"],"backgroundTag":"api-error-response","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}