Kuberwastaken/claurst · critical

failed to build reqwest client

Error message

failed to build reqwest client

What it means

CodexProvider::new builds a reqwest::Client with the workspace request timeout and .expect()s the result, panicking with 'failed to build reqwest client' if the client cannot be constructed. Client construction failing almost always means the TLS backend failed to initialize, so this panic points to a broken build/runtime environment.

Solutions

  1. Enable a TLS backend for reqwest (default-tls or rustls-tls) in the workspace features.
  2. Unify reqwest features with `cargo tree -i reqwest` to remove conflicts.
  3. Use rustls-tls for static/musl/cross builds to avoid OpenSSL issues.
  4. Build the client manually and log the underlying error to diagnose the environment.
  5. Change the constructor to return Result and propagate instead of expect.

Example fix

// before
let http_client = reqwest::Client::builder()
    .timeout(crate::request_timeout())
    .build()
    .expect("failed to build reqwest client");
// after
let http_client = reqwest::Client::builder()
    .timeout(crate::request_timeout())
    .build()
    .context("building Codex HTTP client")?;
Defensive patterns

Strategy: try-catch

Validate before calling

reqwest::Client::builder().timeout(crate::request_timeout()).build()
    .map_err(|e| anyhow!("reqwest TLS unavailable: {e}"))?;

Try / catch

let http_client = reqwest::Client::builder()
    .timeout(crate::request_timeout())
    .build()
    .map_err(|e| anyhow!("failed to build reqwest client: {e}"))?;

Prevention

When it happens

Trigger: Constructing CodexProvider::new(tokens) where reqwest's builder().build() fails — effectively only TLS/backend initialization problems.

Common situations: Binaries built without a TLS feature; cross-compilation with missing OpenSSL; conflicting reqwest feature flags across the dependency graph.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of Kuberwastaken/claurst@b0637c97ec (2026-09-10). Data as JSON: /api/errors/c4add43f55d2d262. Report an issue: GitHub.

Appendix: source

Thrown at src-rust/crates/api/src/providers/codex.rs:58

use crate::providers::copilot::CopilotProvider;

// ---------------------------------------------------------------------------
// CodexProvider
// ---------------------------------------------------------------------------

pub struct CodexProvider {
    id: ProviderId,
    http_client: reqwest::Client,
    /// Mutable token cache: updated in-place when a refresh succeeds.
    tokens: Arc<Mutex<CodexTokens>>,
}

impl CodexProvider {
    pub fn new(tokens: CodexTokens) -> Self {
        let http_client = reqwest::Client::builder()
            .timeout(crate::request_timeout())
            .build()
            .expect("failed to build reqwest client");

        Self {
            id: ProviderId::new(ProviderId::CODEX),
            http_client,
            tokens: Arc::new(Mutex::new(tokens)),
        }
    }

    /// Construct from stored tokens; returns `None` if no tokens are saved.
    pub fn from_stored() -> Option<Self> {
        let tokens = get_codex_tokens()?;
        if tokens.access_token.is_empty() {
            return None;
        }
        Some(Self::new(tokens))
    }

    // -----------------------------------------------------------------------

View on GitHub (pinned to b0637c97ec)