{"record":{"id":"4931acfbe9f2896b","repo":"Kuberwastaken/claurst","slug":"anthropicprovider-from-config-failed-to-create-a","errorCode":null,"errorMessage":"AnthropicProvider::from_config: failed to create AnthropicClient","messagePattern":"AnthropicProvider::from_config: failed to create AnthropicClient","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src-rust/crates/api/src/providers/anthropic.rs","lineNumber":52,"sourceCode":"/// `Arc<dyn LlmProvider>`.\r\npub struct AnthropicProvider {\r\n    client: Arc<AnthropicClient>,\r\n    id: ProviderId,\r\n}\r\n\r\nimpl AnthropicProvider {\r\n    /// Wrap an already-constructed (and Arc-wrapped) [`AnthropicClient`].\r\n    pub fn new(client: Arc<AnthropicClient>) -> Self {\r\n        Self {\r\n            client,\r\n            id: ProviderId::new(ProviderId::ANTHROPIC),\r\n        }\r\n    }\r\n\r\n    /// Construct directly from a [`ClientConfig`], creating the inner client.\r\n    pub fn from_config(config: ClientConfig) -> Self {\r\n        let client = AnthropicClient::new(config)\r\n            .expect(\"AnthropicProvider::from_config: failed to create AnthropicClient\");\r\n        Self {\r\n            client: Arc::new(client),\r\n            id: ProviderId::new(ProviderId::ANTHROPIC),\r\n        }\r\n    }\r\n\r\n    /// Build a [`CreateMessageRequest`] from a [`ProviderRequest`].\r\n    fn build_request(request: &ProviderRequest) -> CreateMessageRequest {\r\n        let normalized_messages = normalize_anthropic_messages(&request.messages);\r\n        let api_messages: Vec<ApiMessage> = normalized_messages\r\n            .iter()\r\n            .map(ApiMessage::from)\r\n            .collect();\r\n\r\n        let api_tools: Option<Vec<ApiToolDefinition>> = if request.tools.is_empty() {\r\n            None\r\n        } else {\r\n            Some(request.tools.iter().map(ApiToolDefinition::from).collect())\r","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/Kuberwastaken/claurst/blob/b0637c97ec34144387cbf2f74f65df6d16a6cef1/src-rust/crates/api/src/providers/anthropic.rs#L34-L70","documentation":"AnthropicProvider::from_config builds an AnthropicClient from the given ClientConfig and calls .expect() on the result, panicking if client construction fails. The panic message surfaces this string. Construction fails when the config cannot produce a valid HTTP client (e.g. TLS backend init failure).","triggerScenarios":"Calling AnthropicProvider::from_config with a ClientConfig whose reqwest client builder fails to build — practically only TLS backend initialization failure, since config shape is fixed.","commonSituations":"Static-linking or cross-compiling without a TLS backend (rustls/native-tls mismatch); running in an environment where OpenSSL cannot be initialized. Note the crate convention elsewhere is to propagate; this expect is an internal invariant.","solutions":["Prefer the fallible constructor (AnthropicClient::new / provider constructors that return Result) and propagate the error instead of relying on from_config.","Check that exactly one TLS backend is available (feature flags: rustls vs native-tls) in your build.","If cross-compiling, ensure the TLS library links correctly for the target.","Enable the `tls` feature of reqwest if all TLS features were disabled.","If this panic fires in practice, capture the underlying reqwest build error by constructing AnthropicClient::new(config) manually and inspecting the Result."],"exampleFix":"// before\nlet provider = AnthropicProvider::from_config(config); // panics on failure\n// after\nlet client = AnthropicClient::new(config).context(\"creating Anthropic client\")?;\nlet provider = AnthropicProvider { client: Arc::new(client), id: ProviderId::new(ProviderId::ANTHROPIC) };","handlingStrategy":"validation","validationCode":"// ensure reqwest has a TLS backend at build time\ncargo tree -i reqwest  # verify default-tls or rustls-tls is enabled\n// and construct the client early with a proper error instead of from_config\nlet client = AnthropicClient::new(config).map_err(|e| anyhow!(\"Anthropic client init failed: {e}\"))?;","typeGuard":null,"tryCatchPattern":"// avoid the panicking path; use the fallible construction and catch it\nmatch AnthropicClient::new(config) {\n    Ok(client) => Ok(AnthropicProvider { client: Arc::new(client), id: ProviderId::new(ProviderId::ANTHROPIC) }),\n    Err(e) => Err(anyhow!(\"failed to create Anthropic client: {e}\")),\n}","preventionTips":["Do not call from_config in library code paths where a panic is unacceptable; construct AnthropicClient directly.","Verify TLS feature flags at build time (rustls-tls or native-tls exactly once).","Smoke-test client construction at startup, before user interaction.","Avoid conflicting reqwest features across workspace dependencies."],"tags":["panic","http-client","tls","configuration"],"backgroundTag":"internal-invariant-violation","analyzedSha":"b0637c97ec34144387cbf2f74f65df6d16a6cef1","analyzedAt":"2026-09-10T00:24:58.650Z","contentChangedAt":"2026-09-10T00:24:58.650Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}