gitbutlerapp/gitbutler · error
Failed to create GitHub stack
Error message
Failed to create GitHub stack: {} What it means
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.
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.
Defensive patterns
Strategy: validation
Validate before calling
// validate PR numbers and access before creating the stack
for pr in &desired {
anyhow::ensure!(pr > 0, "invalid PR number {pr}");
}
anyhow::ensure!(!desired.is_empty(), "stack needs at least one PR");
// optionally confirm each PR exists via the PR fetch API first Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to add to GitHub stack
- Failed to unstack GitHub stack
- Failed to add labels
- Failed to get PR base repo
- Failed to get repo
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/2af6ec6417a7916d.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-github/src/stacks.rs:310
bail!(
"Failed to list GitHub stacks: {}",
response_error(response).await
);
}
Ok(Some(response.json().await?))
}
async fn create_stack(&self, owner: &str, repo: &str, desired: &[i64]) -> Result<()> {
let response = self
.client
.post(format!("{}/repos/{owner}/{repo}/stacks", self.base_url))
.json(&StackMembersBody {
pull_requests: desired,
})
.send()
.await?;
if !response.status().is_success() {
bail!(
"Failed to create GitHub stack: {}",
response_error(response).await
);
}
Ok(())
}
async fn add_to_stack(
&self,
owner: &str,
repo: &str,
stack_number: i64,
pull_requests: &[i64],
) -> Result<()> {
let response = self
.client
.post(format!(
"{}/repos/{owner}/{repo}/stacks/{stack_number}/add",View on GitHub (pinned to 58e5313667)