gitbutlerapp/gitbutler · error

Failed to parse response

Error message

Failed to parse response: {e}

What it means

Thrown when the response body from the update server cannot be deserialized into CheckUpdateStatus via serde_json. The request succeeded with a 2xx status, but the JSON payload does not match the expected schema (missing/renamed fields, wrong types, or non-JSON body).

Solutions

  1. Capture the raw response body and compare it against the CheckUpdateStatus fields to spot schema drift.
  2. Check whether a proxy/captive portal is intercepting the response (body starts with '<' instead of '{').
  3. Update the client application — an old client may be parsing a changed API schema.
  4. If using check_status_with_url against a mock server, fix the mock's response to serialize a valid CheckUpdateStatus.

Example fix

// before
let update_info = response
    .json::<CheckUpdateStatus>()
    .await
    .map_err(|e| anyhow::anyhow!("Failed to parse response: {e}"))?;
// after: include the offending body for diagnosis
let text = response.text().await.map_err(|e| anyhow::anyhow!("Failed to read response: {e}"))?;
let update_info: CheckUpdateStatus = serde_json::from_str(&text)
    .map_err(|e| anyhow::anyhow!("Failed to parse response: {e}; body: {text}"))?;
Defensive patterns

Strategy: fallback

Try / catch

match but_update::check_status(app, &settings, &mut cache) {
    Err(e) if e.to_string().contains("Failed to parse response") => {
        // incompatible/intercepted response: fall back to cached status
        log::warn!("unrecognized update response, using cache");
        Ok(cached_check_result())
    }
    other => other?,
}

Prevention

When it happens

Trigger: check_status/check_status_with_url calling response.json::<CheckUpdateStatus>() when the server returns HTML (e.g. a captive-portal or proxy page), an error body with 200, or JSON whose fields no longer match the CheckUpdateStatus struct (up_to_date, latest_version, release_notes, url, signature).

Common situations: Corporate proxy or captive portal injecting HTML into responses; API contract change between client and server versions; outdated app version talking to a newer update API; a URL override pointing at a mock/test server returning an unexpected body.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at crates/but-update/src/check.rs:132

        let runtime = tokio::runtime::Builder::new_current_thread()
            .enable_all()
            .build()
            .map_err(|e| anyhow::anyhow!("Failed to create runtime: {e}"))?;

        runtime.block_on(async {
            let response = client
                .post(url)
                .json(&request_body)
                .send()
                .await
                .map_err(|e| anyhow::anyhow!("Request failed: {e}"))?
                .error_for_status()
                .map_err(|e| anyhow::anyhow!("Server returned error: {e}"))?;

            let update_info = response
                .json::<CheckUpdateStatus>()
                .await
                .map_err(|e| anyhow::anyhow!("Failed to parse response: {e}"))?;

            Ok(update_info)
        })
    })
    .join()
    .map_err(|_| anyhow::anyhow!("Update check thread panicked"))?;

    // Save to cache (convert to but_db types)
    if let Ok(status) = &result {
        let now = chrono::Utc::now();

        // Get existing cache to preserve suppression
        let existing = trans.update_check().get();
        let (suppressed_at, suppress_duration_hours) = existing
            .and_then(|cached| cached.suppressed_at.zip(cached.suppress_duration_hours))
            .and_then(|(suppressed_at, duration_hours)| {
                let suppress_until = suppressed_at + chrono::Duration::hours(duration_hours as i64);
                if now > suppress_until {

View on GitHub (pinned to 58e5313667)