Kuberwastaken/claurst · critical

failed to build reqwest client

Error message

failed to build reqwest client

What it means

CopilotProvider::new builds a reqwest::Client with the workspace request timeout and .expect()s the result, panicking with 'failed to build reqwest client' if construction fails. This is effectively an internal invariant: reqwest client construction only fails on environment-level problems like a missing TLS backend.

Solutions

  1. Enable a reqwest TLS backend (rustls-tls recommended for portability).
  2. Resolve reqwest feature conflicts via `cargo tree -i reqwest`.
  3. For static targets, use rustls-tls instead of native-tls.
  4. Rebuild the client manually and inspect the reqwest error to find the root cause.
  5. Convert the constructor to return Result and propagate the error.

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 Copilot HTTP client")?;
Defensive patterns

Strategy: try-catch

Validate before calling

reqwest::Client::builder().timeout(crate::request_timeout()).build()
    .map_err(|e| anyhow!("reqwest TLS init failed: {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 CopilotProvider::new(token) in a binary where reqwest's builder fails — TLS backend init failure.

Common situations: No TLS feature enabled in the build graph; cross-compiled/musl binaries missing OpenSSL; container images stripped of CA/TLS libs.

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/3d37a58bb9f803a0. Report an issue: GitHub.

Appendix: source

Thrown at src-rust/crates/api/src/providers/copilot.rs:56

};
use crate::providers::openai::OpenAiProvider;

// ---------------------------------------------------------------------------
// CopilotProvider
// ---------------------------------------------------------------------------

pub struct CopilotProvider {
    id: ProviderId,
    token: String,
    http_client: reqwest::Client,
}

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

        Self {
            id: ProviderId::new(ProviderId::GITHUB_COPILOT),
            token,
            http_client,
        }
    }

    pub fn from_env() -> Option<Self> {
        std::env::var("GITHUB_TOKEN").ok().map(Self::new)
    }

    fn base_url() -> &'static str {
        "https://api.githubcopilot.com"
    }

    fn block_has_image(block: &ContentBlock) -> bool {
        match block {

View on GitHub (pinned to b0637c97ec)