{"record":{"id":"4db4c34d9ca1dd4c","repo":"nautechsystems/nautilus_trader","slug":"failed-to-create-default-bybitrawhttpclient","errorCode":null,"errorMessage":"Failed to create default BybitRawHttpClient","messagePattern":"Failed to create default BybitRawHttpClient","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/bybit/src/http/client.rs","lineNumber":173,"sourceCode":")]\n#[derive(Clone)]\npub struct BybitRawHttpClient {\n    base_url: String,\n    client: Arc<ArcSwap<HttpClient>>,\n    rate_limiter: BybitRateLimiter,\n    credential: Option<Credential>,\n    recv_window_ms: u64,\n    timeout_secs: u64,\n    proxy_url: Option<String>,\n    session_generation: Arc<AtomicU64>,\n    retry_manager: RetryManager<BybitHttpError>,\n    cancellation_token: Arc<parking_lot::Mutex<CancellationToken>>,\n}\n\nimpl Default for BybitRawHttpClient {\n    fn default() -> Self {\n        Self::new(None, 60, 3, 1000, 10_000, DEFAULT_RECV_WINDOW_MS, None)\n            .expect(\"Failed to create default BybitRawHttpClient\")\n    }\n}\n\nimpl Debug for BybitRawHttpClient {\n    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n        f.debug_struct(stringify!(BybitRawHttpClient))\n            .field(\"base_url\", &self.base_url)\n            .field(\"has_credentials\", &self.credential.is_some())\n            .field(\"recv_window_ms\", &self.recv_window_ms)\n            .finish()\n    }\n}\n\nimpl BybitRawHttpClient {\n    /// Cancels all pending HTTP requests.\n    pub fn cancel_all_requests(&self) {\n        self.cancellation_token.lock().cancel();\n    }","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bybit/src/http/client.rs#L155-L191","documentation":"BybitRawHttpClient::default() calls Self::new with sensible defaults (60s timeout, 3 retries, etc.) and expects success. new only fails on invalid configuration, so with these fixed defaults it cannot fail; the expect turns any such failure into a panic at client construction. Users hit a panic during Default/Geo init rather than a returned error.","triggerScenarios":"Calling BybitRawHttpClient::default() (or code paths that use it) when the underlying new() fails — realistically only if environment/proxy/TLS setup makes even the default configuration invalid (e.g. reqwest client cannot build due to TLS backend issues).","commonSituations":"Embedded environments or musl builds where the TLS backend fails to initialize; a static proxy config that reqwest rejects at client build time; running in a context where Default is invoked implicitly.","solutions":["Call BybitRawHttpClient::new(None, 60, 3, 1000, 10_000, DEFAULT_RECV_WINDOW_MS, None)? directly and handle the error","Check the error message from new() for TLS/proxy/root-certificate issues in your environment","Ensure the correct TLS feature (native-tls vs rustls) is enabled for your target platform","Avoid Default in fallible contexts; construct explicitly and propagate the error"],"exampleFix":"// before\nlet client = BybitRawHttpClient::default(); // panics on failure\n// after\nlet client = BybitRawHttpClient::new(\n    None, 60, 3, 1000, 10_000, DEFAULT_RECV_WINDOW_MS, None,\n)?;","handlingStrategy":"try-catch","validationCode":"// construct explicitly instead of relying on Default\nlet client = BybitRawHttpClient::new(\n    None, 60, 3, 1000, 10_000, DEFAULT_RECV_WINDOW_MS, None,\n)?;","typeGuard":null,"tryCatchPattern":"let client = BybitRawHttpClient::new(\n    None, 60, 3, 1000, 10_000, DEFAULT_RECV_WINDOW_MS, None,\n)\n.map_err(|e| {\n    eprintln!(\"Bybit HTTP client init failed: {e}\");\n    e\n})?;","preventionTips":["Avoid Default for clients in fallible environments; construct explicitly","Verify TLS backend availability on your target (musl/cross-compile) before deploying","Log the underlying error from new() rather than only seeing the panic message"],"tags":["panic","http-client","initialization","bybit"],"backgroundTag":"module-init-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}