{"record":{"id":"f50bd2c57486de9c","repo":"Hmbown/CodeWhale","slug":"failed-to-build-http-client","errorCode":null,"errorMessage":"failed to build HTTP client","messagePattern":"failed to build HTTP client","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/finance.rs","lineNumber":160,"sourceCode":"    fn summary(&self) -> String {\n        format!(\"{}: {}\", self.endpoint, self.detail)\n    }\n}\n\npub struct FinanceTool {\n    endpoints: FinanceEndpoints,\n    client: Client,\n}\n\nimpl FinanceTool {\n    #[must_use]\n    pub fn new() -> Self {\n        Self {\n            endpoints: FinanceEndpoints::default(),\n            client: crate::tls::reqwest_client_builder()\n                .user_agent(USER_AGENT)\n                .build()\n                .expect(\"failed to build HTTP client\"),\n        }\n    }\n\n    #[cfg(test)]\n    fn with_endpoints(quote_base: impl Into<String>, chart_base: impl Into<String>) -> Self {\n        Self {\n            endpoints: FinanceEndpoints {\n                quote_base: quote_base.into(),\n                chart_base: chart_base.into(),\n            },\n            client: crate::tls::reqwest_client_builder()\n                .user_agent(USER_AGENT)\n                .build()\n                .expect(\"failed to build HTTP client\"),\n        }\n    }\n}\n","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/finance.rs#L142-L178","documentation":"`FinanceTool::new()` builds a reqwest HTTP client via `crate::tls::reqwest_client_builder().user_agent(USER_AGENT).build()` and unwraps the result with `expect(\"failed to build HTTP client\")`. reqwest's `build()` fails when the TLS backend cannot be initialized (e.g. native-tls cannot load the system OpenSSL, or rustls cannot be constructed) or when a user-agent header value is invalid. The tool treats client construction as a hard precondition, so failure panics instead of returning a Result.","triggerScenarios":"Calling `FinanceTool::new()` (or `with_endpoints`) in an environment where the TLS backend init fails: missing/broken OpenSSL shared libraries, a rustls crypto provider misconfiguration, or `USER_AGENT` containing characters invalid for a header value.","commonSituations":"Deploying to a slim/container image without CA certificates or OpenSSL; cross-compiling with a TLS backend not linked for the target; corrupting the USER_AGENT constant during an edit.","solutions":["Verify the TLS backend is available in the deployment environment (install ca-certificates / libssl matching the target, or switch the builder to rustls with a working crypto provider).","Reproduce locally by calling `crate::tls::reqwest_client_builder().build()` and inspect the returned reqwest::Error for the root cause.","If the panic is unacceptable in your context, add a fallible constructor (try_new -> Result) and surface the error instead of panicking.","Check USER_AGENT for non-visible-ASCII characters that make the header value invalid."],"exampleFix":"// before\nclient: crate::tls::reqwest_client_builder()\n    .user_agent(USER_AGENT)\n    .build()\n    .expect(\"failed to build HTTP client\"),\n// after\nclient: crate::tls::reqwest_client_builder()\n    .user_agent(USER_AGENT)\n    .build()\n    .map_err(|e| ToolInitError::HttpClient(format!(\"finance tool init: {e}\")))?,","handlingStrategy":"fallback","validationCode":"// At startup, before constructing FinanceTool:\nlet probe = crate::tls::reqwest_client_builder().build();\nif let Err(e) = probe { eprintln!(\"TLS/HTTP client unavailable: {e}\"); }\n","typeGuard":null,"tryCatchPattern":"// If you must call new() in fallible context:\nlet tool = std::panic::catch_unwind(FinanceTool::new)\n    .map_err(|_| anyhow::anyhow!(\"finance tool unavailable: HTTP client init failed\"))?;","preventionTips":["Ensure ca-certificates and the TLS backend libs are present in deployment images.","Smoke-test client construction at process start rather than first tool use.","Prefer a try_new() -> Result constructor for tools built from environment-dependent TLS state.","Keep USER_AGENT printable ASCII."],"tags":["rust","http","reqwest","tls","panic"],"backgroundTag":"http-request-failed","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}