{"record":{"id":"58290a47c23caa5c","repo":"gitbutlerapp/gitbutler","slug":"github-returned-an-error","errorCode":null,"errorMessage":"GitHub returned an error: {} ({})","messagePattern":"GitHub returned an error: (.+?) \\((.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-github/src/lib.rs","lineNumber":41,"sourceCode":"\n#[cfg_attr(feature = \"export-schema\", derive(schemars::JsonSchema))]\n#[derive(Debug, Deserialize, Serialize, Clone, Default)]\npub struct Verification {\n    pub user_code: String,\n    pub device_code: String,\n}\n#[cfg(feature = \"export-schema\")]\nbut_schemars::register_sdk_type!(Verification);\n\n/// 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.\nfn parse_github_oauth_response<T: serde::de::DeserializeOwned>(body: &str) -> Result<T> {\n    let value: serde_json::Value =\n        serde_json::from_str(body).context(\"Response body was not valid JSON\")?;\n    if let Some(error) = value.get(\"error\").and_then(serde_json::Value::as_str) {\n        let description = value\n            .get(\"error_description\")\n            .and_then(serde_json::Value::as_str);\n        let err = anyhow::anyhow!(\n            \"GitHub returned an error: {} ({})\",\n            error,\n            description.unwrap_or(\"no description\"),\n        );\n        return Err(match device_flow_context(error) {\n            Some(context) => err.context(context),\n            None => err,\n        });\n    }\n    serde_json::from_value(value).context(\"Response body did not match expected schema\")\n}\n\n/// A static, code-bearing context for terminal device-flow statuses, so the API serializes\n/// guidance instead of GitHub's description. Pending statuses stay as they are: callers poll\n/// through them, and the provider text remains the inner error for the CLI and Lite.\nfn device_flow_context(status: &str) -> Option<but_error::Context> {\n    use but_error::{Code, Context};\n    match status {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-github/src/lib.rs#L23-L59","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Retry the flow after the device-flow interval; authorization_pending clears once the user approves","Complete the browser authorization at github.com/login/device before the code expires","Restart `but config forge auth` to get a fresh device code if it expired","Respect the slow_down interval increase before the next poll","If access_denied, the user must re-run and approve the request"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match res {\n    Err(e) if e.to_string().contains(\"authorization_pending\") => continue_polling(interval),\n    Err(e) if e.to_string().contains(\"slow_down\") => { interval += 5; continue_polling(interval) }\n    Err(e) if e.to_string().contains(\"expired_token\") => restart_device_flow(),\n    Err(e) => return Err(e),\n}","preventionTips":["Poll no faster than the GitHub-specified interval and honor slow_down","Complete browser approval promptly; device codes expire quickly","Treat access_denied as terminal and restart the flow"],"tags":["oauth","github","device-flow","network"],"backgroundTag":"oauth-token-exchange-failed","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}