gitbutlerapp/gitbutler · error
Failed to unstack GitHub stack
Error message
Failed to unstack GitHub stack: {} What it means
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.
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.
Defensive patterns
Strategy: try-catch
Validate before calling
let stacks = stacks_client.existing_stacks(owner, repo, pr).await?;
anyhow::ensure!(stacks.iter().any(|s| s.number == stack_number), "stack {stack_number} already gone"); Try / catch
match stacks.unstack(owner, repo, stack_number).await {
Ok(()) => (),
Err(e) if e.to_string().contains("404") => (), // already unstacked — idempotent success
Err(e) => return Err(e),
} Prevention
- Treat 404 on unstack as success (idempotency).
- Avoid caching stack numbers across sessions.
- Refresh credentials before batch stack mutations.
- Retry 5xx with backoff.
When it happens
Trigger: 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.
Common situations: The stack was already unstacked in another session or via the GitHub UI (404); token revocation; GHES instance lacking the endpoint.
Related errors
- Failed to add to GitHub stack
- Failed to create 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/affd04569c90f26e.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-github/src/stacks.rs:353
bail!(
"Failed to add to GitHub stack: {}",
response_error(response).await
);
}
Ok(())
}
async fn unstack(&self, owner: &str, repo: &str, stack_number: i64) -> Result<()> {
let response = self
.client
.post(format!(
"{}/repos/{owner}/{repo}/stacks/{stack_number}/unstack",
self.base_url
))
.send()
.await?;
if !response.status().is_success() {
bail!(
"Failed to unstack GitHub stack: {}",
response_error(response).await
);
}
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
fn stack(number: i64, members: &[i64]) -> Stack {
Stack {
number,
pull_requests: members
.iter()
.map(|number| StackPullRequest {View on GitHub (pinned to 58e5313667)