Hmbown/CodeWhale · error

Codewhale account request failed

Error message

Codewhale account request failed (HTTP {})

What it means

Variant of error 2031: the Codewhale account API returned a non-success HTTP status but no usable machine error code could be extracted from the response body (missing `code` field or code rejected by `safe_error_code`). Only the HTTP status is reported.

Solutions

  1. Act on the HTTP status: 401/403 → re-authenticate; 429 → back off; 5xx → retry later.
  2. Re-run `codewhale login` to refresh the account key.
  3. Check network intermediaries (corporate proxies) that may replace error bodies.
  4. Upgrade the CLI, then retry; report the raw status if it persists.
Defensive patterns

Strategy: retry

Try / catch

// status-only failure (no server error code): inspect status, retry transient ones
if let Err(e) = call() {
    let msg = e.to_string();
    if msg.contains("HTTP 5") || msg.contains("HTTP 429") { retry_with_backoff(); }
    else if msg.contains("HTTP 401") || msg.contains("HTTP 403") { reauth(); }
    else { return Err(e); }
}

Prevention

When it happens

Trigger: Same as 2031 — any failing account API request — but the response JSON lacks a `code` string field, is not valid JSON, or the code value fails `safe_error_code`.

Common situations: Gateway/proxy error pages (HTML bodies), older server versions not emitting `code`, or malformed error responses during outages.

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 Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/d13669daf41676ff. Report an issue: GitHub.

Appendix: source

Thrown at crates/cli/src/cloud.rs:1264

fn response_error(response: &CloudResponse) -> anyhow::Error {
    let code = serde_json::from_slice::<serde_json::Value>(&response.body)
        .ok()
        .and_then(|body| {
            body.get("code")
                .and_then(serde_json::Value::as_str)
                .or_else(|| {
                    body.get("error")
                        .and_then(|error| error.get("code"))
                        .and_then(serde_json::Value::as_str)
                })
                .and_then(safe_error_code)
        });
    match code {
        Some(code) => anyhow!(
            "Codewhale account request failed (HTTP {}, code {code})",
            response.status
        ),
        None => anyhow!(
            "Codewhale account request failed (HTTP {})",
            response.status
        ),
    }
}

fn safe_error_code(code: &str) -> Option<String> {
    if code.is_empty()
        || code.len() > 80
        || !code
            .bytes()
            .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'_' | b'-' | b'.'))
    {
        return None;
    }
    Some(code.to_string())
}

View on GitHub (pinned to 433685b202)