Hmbown/CodeWhale · error · MachineError

Could not reach the Codewhale service

Error message

Could not reach the Codewhale service: {}

What it means

send_with_retry wraps cloud transport calls; when transport.execute returns Err (no HTTP response at all — DNS failure, refused connection, TLS error, timeout at the transport layer), it builds a transport MachineError with this message. Idempotent requests are retried with backoff before the error surfaces.

Solutions

  1. Check network connectivity and that the Codewhale service URL is correct
  2. Verify the service is up (status page or health endpoint)
  3. Check proxy/VPN/firewall settings and TLS certificates
  4. Retry later if it is a transient outage — idempotent calls already retry with backoff

Example fix

// ensure base URL is reachable before calling
let url = std::env::var("CODEWHALE_SERVICE_URL")?;
reqwest::get(format!("{url}/health")).await
    .context("Codewhale service unreachable — check URL/network")?;
Defensive patterns

Strategy: retry

Validate before calling

// pre-flight reachability check
reqwest::get(format!("{base}/health")).await.map_err(|e| format!("service unreachable: {e}"))?;

Try / catch

match send_with_retry(...) {
    Ok(resp) => resp,
    Err(e) if e.to_string().contains("Could not reach the Codewhale service") => {
        // transport-layer failure: check connectivity, then retry or fail gracefully
        eprintln!("offline or wrong service URL; retry later");
        default_value
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Any cloud API call (e.g. get_json) when the machine cannot connect to the Codewhale service: service down, wrong base URL, DNS failure, firewall, TLS handshake failure, or local network outage.

Common situations: Offline development; corporate proxies blocking the endpoint; mistyped CODEWHALE service URL; service outage during `codewhale account` operations.

Understand the failure class

Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/70af930601ec665b. Report an issue: GitHub.

Appendix: source

Thrown at crates/cli/src/cloud/machine.rs:719

    retry: Retry,
    sleeper: &mut dyn FnMut(Duration),
    build: impl Fn() -> CloudRequest,
) -> Result<CloudResponse> {
    let max_attempts = if retry == Retry::Idempotent {
        MAX_ATTEMPTS
    } else {
        1
    };
    let mut attempt = 1;
    loop {
        let (error, retry_after) = match transport.execute(build()) {
            Ok(response) if (200..300).contains(&response.status) => return Ok(response),
            Ok(response) => {
                let retry_after = response.retry_after;
                (classify(&response), retry_after)
            }
            Err(err) => (
                MachineError::transport(format!(
                    "Could not reach the Codewhale service: {}",
                    printable(&err.to_string())
                )),
                None,
            ),
        };
        if !error.retryable || attempt >= max_attempts {
            return Err(anyhow::Error::new(error));
        }
        sleeper(backoff_delay(attempt, retry_after));
        attempt += 1;
    }
}

fn decode_json<R: serde::de::DeserializeOwned>(response: CloudResponse) -> Result<R> {
    serde_json::from_slice(&response.body)
        .context("The Codewhale service returned an invalid JSON response")
}

View on GitHub (pinned to 73e0f67d83)