{"record":{"id":"2af6ec6417a7916d","repo":"gitbutlerapp/gitbutler","slug":"failed-to-create-github-stack","errorCode":null,"errorMessage":"Failed to create GitHub stack: {}","messagePattern":"Failed to create GitHub stack: (.+?)","errorType":"http","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/but-github/src/stacks.rs","lineNumber":310,"sourceCode":"            bail!(\n                \"Failed to list GitHub stacks: {}\",\n                response_error(response).await\n            );\n        }\n        Ok(Some(response.json().await?))\n    }\n\n    async fn create_stack(&self, owner: &str, repo: &str, desired: &[i64]) -> Result<()> {\n        let response = self\n            .client\n            .post(format!(\"{}/repos/{owner}/{repo}/stacks\", self.base_url))\n            .json(&StackMembersBody {\n                pull_requests: desired,\n            })\n            .send()\n            .await?;\n        if !response.status().is_success() {\n            bail!(\n                \"Failed to create GitHub stack: {}\",\n                response_error(response).await\n            );\n        }\n        Ok(())\n    }\n\n    async fn add_to_stack(\n        &self,\n        owner: &str,\n        repo: &str,\n        stack_number: i64,\n        pull_requests: &[i64],\n    ) -> Result<()> {\n        let response = self\n            .client\n            .post(format!(\n                \"{}/repos/{owner}/{repo}/stacks/{stack_number}/add\",","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but-github/src/stacks.rs#L292-L328","documentation":"POST /repos/{o}/{r}/stacks with the desired pull-request list returned a non-2xx status; the wrapped response body carries GitHub's reason for refusing to create the stack.","triggerScenarios":"A listed PR is closed, invalid, or from another repo; the PRs cannot form a stack (branches not chained); the acting user lacks permission to manage stacks; a PR is already in a different stack; rate limits.","commonSituations":"Trying to stack unrelated PRs; stale PR numbers; concurrent stack edits from other clients.","solutions":["Read the wrapped body - it names the invalid PR or the violated constraint","Ensure all PRs are open in the same repo and form a parent/child branch chain","Remove conflicting stack membership before creating","Back off on 429/5xx and retry"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"let prs = client.list_pull_requests(owner, repo, &Default::default()).await?;\nlet all_open = desired.iter().all(|n| prs.iter().any(|pr| &pr.number == n && pr.state == PrState::Open));\nif !all_open { anyhow::bail!(\"stack creation requires all PRs to be open in {owner}/{repo}\"); }","typeGuard":null,"tryCatchPattern":"if let Err(e) = client.create_stack(owner, repo, &desired).await {\n    if e.to_string().starts_with(\"Failed to create GitHub stack\") {\n        // body text names the offending PR: surface it verbatim\n        return Err(e.context(format!(\"creating stack for PRs {desired:?}\")));\n    }\n    return Err(e);\n}","preventionTips":["Verify every PR number is open and in the same repo before stacking","Build stacks from chained branches only","Resolve conflicting stack membership before creating a new stack"],"tags":["github","stacks","rest-api","pull-request"],"backgroundTag":"github-api-request-failed","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}