{"record":{"id":"05fcebcfc519a25d","repo":"nautechsystems/nautilus_trader","slug":"failed-to-create-default-bybithttpclient","errorCode":null,"errorMessage":"Failed to create default BybitHttpClient","messagePattern":"Failed to create default BybitHttpClient","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/bybit/src/http/client.rs","lineNumber":1611,"sourceCode":"    use_spot_position_reports: Arc<AtomicBool>,\n}\n\nimpl Clone for BybitHttpClient {\n    fn clone(&self) -> Self {\n        Self {\n            inner: self.inner.clone(),\n            instruments_cache: self.instruments_cache.clone(),\n            cache_initialized: self.cache_initialized.clone(),\n            use_spot_position_reports: self.use_spot_position_reports.clone(),\n            clock: self.clock,\n        }\n    }\n}\n\nimpl Default for BybitHttpClient {\n    fn default() -> Self {\n        Self::new(None, 60, 3, 1000, 10_000, DEFAULT_RECV_WINDOW_MS, None)\n            .expect(\"Failed to create default BybitHttpClient\")\n    }\n}\n\nimpl Debug for BybitHttpClient {\n    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n        f.debug_struct(stringify!(BybitHttpClient))\n            .field(\"inner\", &self.inner)\n            .finish()\n    }\n}\n\nimpl BybitHttpClient {\n    /// Creates a new [`BybitHttpClient`] using the default Bybit HTTP URL.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the retry manager cannot be created.\n    pub fn new(","sourceCodeStart":1593,"sourceCodeEnd":1629,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bybit/src/http/client.rs#L1593-L1629","documentation":"`impl Default for BybitHttpClient` calls `Self::new(None, 60, 3, 1000, 10_000, DEFAULT_RECV_WINDOW_MS, None)` and unwraps with `expect`. This panics if `BybitHttpClient::new` fails — typically invalid configuration such as an unusable proxy URL, invalid timeouts, or internal construction failure (e.g. TLS/client builder error).","triggerScenarios":"Using `BybitHttpClient::default()` (or `Default::default()`) in an environment where the underlying HTTP client cannot be constructed — e.g. a misconfigured proxy env var (HTTPS_PROXY) pointing at an invalid URL, or reqwest failing to build its TLS backend.","commonSituations":"Corporate proxies with malformed `HTTPS_PROXY`/`HTTP_PROXY` values; restricted environments without TLS roots; embedding in services that construct the client via `Default` without validation.","solutions":["Call `BybitHttpClient::new(...)` directly and handle the `Result` instead of relying on `Default`","Check proxy environment variables (`HTTPS_PROXY`, `HTTP_PROXY`, `ALL_PROXY`) for malformed URLs and unset or fix them","Verify the runtime has valid TLS/CA roots for reqwest","Log the underlying `BybitHttpError` from `new` to identify the exact construction failure"],"exampleFix":"// before\nlet client = BybitHttpClient::default();\n// after\nlet client = BybitHttpClient::new(None, 60, 3, 1000, 10_000, DEFAULT_RECV_WINDOW_MS, None)?;","handlingStrategy":"try-catch","validationCode":"// Avoid Default in proxy-heavy environments; construct explicitly and validate env first\nfor v in [\"HTTPS_PROXY\", \"HTTP_PROXY\", \"ALL_PROXY\"] {\n    if let Ok(p) = std::env::var(v) {\n        assert!(p.starts_with(\"http://\") || p.starts_with(\"https://\"), \"malformed proxy: {v}={p}\");\n    }\n}","typeGuard":null,"tryCatchPattern":"// Replace default() with explicit construction and error handling:\nlet client = BybitHttpClient::new(None, 60, 3, 1000, 10_000, DEFAULT_RECV_WINDOW_MS, None)\n    .map_err(|e| { log::error!(\"client init failed: {e}\"); e })?;","preventionTips":["Never rely on Default for clients in production; construct via new() and handle Result","Sanity-check proxy env vars before service startup","Pin and test TLS/CA setup in container images"],"tags":["panic","http-client","initialization","proxy"],"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-14T00:17:10.932Z"}