gitbutlerapp/gitbutler · error

GitHub returned an error

Error message

GitHub returned an error: {} ({})

What it means

Raised while parsing the GitHub OAuth device-flow token response when the JSON body contains an `error` field, meaning GitHub rejected the token request (e.g. authorization_pending, slow_down, expired_token, access_denied). The error text embeds GitHub's error code and description, and device_flow_context attaches extra guidance for known device-flow errors.

Solutions

  1. Retry the flow after the device-flow interval; authorization_pending clears once the user approves
  2. Complete the browser authorization at github.com/login/device before the code expires
  3. Restart `but config forge auth` to get a fresh device code if it expired
  4. Respect the slow_down interval increase before the next poll
  5. If access_denied, the user must re-run and approve the request
Defensive patterns

Strategy: retry

Try / catch

match res {
    Err(e) if e.to_string().contains("authorization_pending") => continue_polling(interval),
    Err(e) if e.to_string().contains("slow_down") => { interval += 5; continue_polling(interval) }
    Err(e) if e.to_string().contains("expired_token") => restart_device_flow(),
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: init_github_device_oauth polls the GitHub OAuth token endpoint and the response body has a non-null `error` field — typically while the user has not yet typed the code, polling too fast (slow_down), the device code expired, or the user denied access.

Common situations: User closes the browser before approving; device code TTL expires during long waits; client polls faster than the interval so GitHub returns slow_down; intermittent 5xx from GitHub rendered as an error payload.

Related errors


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

Appendix: source

Thrown at crates/but-github/src/lib.rs:41

#[cfg_attr(feature = "export-schema", derive(schemars::JsonSchema))]
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
pub struct Verification {
    pub user_code: String,
    pub device_code: String,
}
#[cfg(feature = "export-schema")]
but_schemars::register_sdk_type!(Verification);

/// Detect GitHub's OAuth error shape (e.g. `device_flow_disabled`, `authorization_pending`) before falling back to the expected payload, so the real cause surfaces instead of a generic "missing field" serde error.
fn parse_github_oauth_response<T: serde::de::DeserializeOwned>(body: &str) -> Result<T> {
    let value: serde_json::Value =
        serde_json::from_str(body).context("Response body was not valid JSON")?;
    if let Some(error) = value.get("error").and_then(serde_json::Value::as_str) {
        let description = value
            .get("error_description")
            .and_then(serde_json::Value::as_str);
        let err = anyhow::anyhow!(
            "GitHub returned an error: {} ({})",
            error,
            description.unwrap_or("no description"),
        );
        return Err(match device_flow_context(error) {
            Some(context) => err.context(context),
            None => err,
        });
    }
    serde_json::from_value(value).context("Response body did not match expected schema")
}

/// A static, code-bearing context for terminal device-flow statuses, so the API serializes
/// guidance instead of GitHub's description. Pending statuses stay as they are: callers poll
/// through them, and the provider text remains the inner error for the CLI and Lite.
fn device_flow_context(status: &str) -> Option<but_error::Context> {
    use but_error::{Code, Context};
    match status {

View on GitHub (pinned to 58e5313667)