gitbutlerapp/gitbutler · error

Failed to list GitHub stacks

Error message

Failed to list GitHub stacks: {}

What it means

The GitHub REST call used by `stacks_for_pull_request` (via `existing_stacks`) returned a non-success, non-404 status. The client includes GitHub's response body (rendered by `response_error`) as the error detail, so the underlying cause is in the `{}` text.

Solutions

  1. Read the status/body embedded in the message — it names the precise cause.
  2. If 401/403, refresh the GitHub token and ensure it has `repo` scope and access to the repository.
  3. If 404 keeps appearing unexpectedly, verify owner/repo spelling and that the correct base_url is configured (github.com vs GHES).
  4. If 5xx, check the GitHub status page and retry with backoff.
Defensive patterns

Strategy: try-catch

Validate before calling

// validate configuration and access before listing stacks
anyhow::ensure!(!token.is_empty(), "GitHub token missing");
anyhow::ensure!(owner_repo_matches("^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$"), "bad owner/repo");

Try / catch

match stacks.existing_stacks(owner, repo, pr).await {
    Ok(Some(stacks)) => use(stacks),
    Ok(None) => handle_no_stack(), // 404 path
    Err(e) if e.to_string().contains("401") || e.to_string().contains("403") => refresh_credentials(),
    Err(e) => retry_or_surface(e),
}

Prevention

When it happens

Trigger: Calling existing_stacks/stacks_for_pull_request when the stack API endpoint responds 4xx/5xx — e.g. 401/403 for bad token or missing access to the repo, 404 only handled separately (returns Ok(None)), 422 for a bad owner/repo/PR, 5xx for GitHub-side issues.

Common situations: Token expired or lacking `repo` scope; wrong base_url (GitHub Enterprise misconfiguration) pointing at a non-GitHub server; typo'd owner/repo; GitHub incident returning 5xx.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/0594efebdd3d48d3. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-github/src/stacks.rs:292

impl GitHubClient {
    /// `Ok(None)` means the repository does not expose the native stacks endpoint.
    async fn stacks_for_pull_request(
        &self,
        owner: &str,
        repo: &str,
        review_number: i64,
    ) -> Result<Option<Vec<Stack>>> {
        let response = self
            .client
            .get(format!("{}/repos/{owner}/{repo}/stacks", self.base_url))
            .query(&[("pull_request", review_number)])
            .send()
            .await?;
        if response.status() == reqwest::StatusCode::NOT_FOUND {
            return Ok(None);
        }
        if !response.status().is_success() {
            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!(

View on GitHub (pinned to 58e5313667)