gitbutlerapp/gitbutler · error

GitHub GraphQL returned errors

Error message

GitHub GraphQL returned errors: {messages}

What it means

The GitHub GraphQL API responded successfully at the HTTP level but the response payload contained a top-level `errors` array, meaning GraphQL rejected or partially failed the query. The client joins all error messages with "; " and surfaces them so the caller sees GitHub's actual reason (e.g. throttling, bad nodes, permission issues).

Solutions

  1. Read the joined message(s) in the error text — GitHub names the exact field and error code (e.g. FORBIDDEN, NOT_FOUND, RATE_LIMITED).
  2. If RATE_LIMITED or throttling, wait until the rate-limit reset and add request pacing or reduce query cost.
  3. If FORBIDDEN/INSUFFICIENT_SCOPES, regenerate the token with the required scopes (repo / workflow as needed).
  4. If NOT_FOUND on a node, verify the PR number/owner/repo and that the entity still exists.
  5. If a field is unknown, update the GraphQL query to match the current GitHub schema.

Example fix

// before: fire-and-forget GraphQL call that may be rate limited
let prs = client.pull_request_node_id(owner, repo, number).await?;

// after: pre-flight a rate-limit check so GraphQL errors surface with context
let remaining = client.rate_limit_remaining().await?;
anyhow::ensure!(remaining > 0, "GitHub GraphQL rate limit exhausted");
let prs = client.pull_request_node_id(owner, repo, number).await?;
Defensive patterns

Strategy: try-catch

Validate before calling

// Rust: pre-check inputs and rate limit before the GraphQL call
anyhow::ensure!(!owner.is_empty() && !repo.is_empty(), "owner/repo required");
// optionally: ensure!(client.rate_limit_remaining().await? > 0, "GraphQL rate limit exhausted");

Try / catch

match client.pull_request_node_id(owner, repo, number).await {
    Ok(id) => use(id),
    Err(e) if e.to_string().contains("RATE_LIMITED") => schedule_retry_after_reset(),
    Err(e) if e.to_string().contains("NOT_FOUND") => handle_missing_pr(),
    Err(e) => log_and_surface(e),
}

Prevention

When it happens

Trigger: Any GraphQL query/mutation executed by crates/but-github's client (e.g. fetching PR node IDs or other PR data) where GitHub returns `errors` in the JSON payload — typically malformed queries, missing fields, resource-not-found node IDs, or rate-limit/throttle errors.

Common situations: Expired or insufficiently scoped token causing FORBIDDEN/INSUFFICIENT_SCOPES on a field; querying a PR that was deleted or is private; hitting GitHub GraphQL rate limits (query cost); a bug in the hand-written GraphQL query string after an API schema change.

Related errors


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

Appendix: source

Thrown at crates/but-github/src/client.rs:1852

    struct GraphQlError {
        message: String,
    }

    #[derive(Deserialize)]
    struct GraphQlResponse {
        data: Option<serde_json::Value>,
        errors: Option<Vec<GraphQlError>>,
    }

    let payload: GraphQlResponse = serde_json::from_slice(body)?;

    if let Some(errors) = payload.errors {
        let messages = errors
            .into_iter()
            .map(|error| error.message)
            .collect::<Vec<_>>()
            .join("; ");
        bail!("GitHub GraphQL returned errors: {messages}");
    }

    let Some(data) = payload.data else {
        bail!("GitHub GraphQL response did not include data");
    };

    Ok(serde_json::from_value(data)?)
}

pub struct PullRequestNodeId {
    id: String,
}

impl PullRequestNodeId {
    pub fn from_string(value: String) -> Self {
        PullRequestNodeId { id: value }
    }
}

View on GitHub (pinned to 58e5313667)