{"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":null,"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/58e5313667b857ef39a730e380af31816a7b1768/crates/but-github/src/stacks.rs#L292-L328","documentation":"The REST request to create a GitHub stack failed with a non-success HTTP status; the response body (via `response_error`) is embedded in the message. Stack creation associates a set of pull requests as stack members on GitHub's side.","triggerScenarios":"Calling create_stack when POST to `{base_url}/repos/{owner}/{repo}/stacks` (or equivalent) returns 4xx/5xx — bad credentials, missing repo access, invalid pull_request numbers in StackMembersBody, or GitHub server errors.","commonSituations":"Token missing permissions for the target repo; referencing PR numbers that don't exist or belong to another repo; GHES instance without the stacks endpoint (older version) returning 404/405.","solutions":["Inspect the embedded status/body for the exact failure reason.","If 401/403, fix token scopes/access for the repository.","Validate every PR number in the desired stack exists in owner/repo before calling.","If 404/405, confirm the GitButler stacks API is available on the configured GitHub instance (GHES version support).","Retry with backoff on 5xx."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// validate PR numbers and access before creating the stack\nfor pr in &desired {\n    anyhow::ensure!(pr > 0, \"invalid PR number {pr}\");\n}\nanyhow::ensure!(!desired.is_empty(), \"stack needs at least one PR\");\n// optionally confirm each PR exists via the PR fetch API first","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Confirm every PR in StackMembersBody exists in owner/repo and is open.","Validate token permissions for the repo before stack mutations.","Confirm the GHES instance supports the stacks endpoints.","Retry only on 5xx, never on 422 validation errors."],"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"}