{"record":{"id":"488c9108f059daba","repo":"nautechsystems/nautilus_trader","slug":"failed-to-build-client-e","errorCode":null,"errorMessage":"Failed to build client: {e}","messagePattern":"Failed to build client: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/databento/src/historical.rs","lineNumber":112,"sourceCode":"    }\n\n    /// Creates a new [`DatabentoHistoricalClient`] instance.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if client creation or publisher loading fails.\n    pub fn new(\n        credential: Credential,\n        publishers_filepath: PathBuf,\n        clock: &'static AtomicTime,\n        use_exchange_as_venue: bool,\n    ) -> anyhow::Result<Self> {\n        let client = databento::HistoricalClient::builder()\n            .user_agent_extension(NAUTILUS_USER_AGENT.into())\n            .key(credential.api_key())\n            .map_err(|e| anyhow::anyhow!(\"Failed to create client builder: {e}\"))?\n            .build()\n            .map_err(|e| anyhow::anyhow!(\"Failed to build client: {e}\"))?;\n\n        Self::from_client(\n            credential,\n            publishers_filepath,\n            clock,\n            use_exchange_as_venue,\n            client,\n        )\n    }\n\n    /// Creates a new [`DatabentoHistoricalClient`] instance with a custom API base URL.\n    ///\n    /// This is intended for tests, benchmarks, and controlled deployments that route\n    /// Databento Historical API requests through a proxy.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if client creation, URL parsing, or publisher loading fails.","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/databento/src/historical.rs#L94-L130","documentation":"Wraps any error returned by the databento crate's HistoricalClient builder's `.build()` step into an anyhow error with a unified message. The underlying databento error is preserved via Display in the message. Thrown from `DatabentoHistoricalClient::new` when the configured builder cannot construct a client (e.g. invalid API key format).","triggerScenarios":"Calling `DatabentoHistoricalClient::new(credential, ...)` where the credential's API key is rejected by the databento builder's build() validation (e.g. empty or malformed key).","commonSituations":"Expired or revoked Databento API keys, keys copied with whitespace, using an environment variable that is unset/empty so the key resolves to an invalid value.","solutions":["Print/log the underlying `{e}` to see the exact databento builder error","Verify the API key is non-empty, correctly formatted, and active on your Databento account","Re-export the DATABENTO_API_KEY environment variable and rebuild the credential","Check databento crate version for changed builder build() requirements"],"exampleFix":"// before\nlet key = std::env::var(\"DATABENTO_API_KEY\").unwrap_or_default();\n// after\nlet key = std::env::var(\"DATABENTO_API_KEY\").expect(\"DATABENTO_API_KEY must be set\");\nlet key = key.trim();\nassert!(!key.is_empty(), \"DATABENTO_API_KEY is empty\");","handlingStrategy":"try-catch","validationCode":"let key = std::env::var(\"DATABENTO_API_KEY\")?;\nif key.trim().is_empty() { return Err(anyhow::anyhow!(\"DATABENTO_API_KEY is empty\")); }","typeGuard":"fn has_api_key(cred: &Credentials) -> bool { !cred.api_key().trim().is_empty() }","tryCatchPattern":"match DatabentoHistoricalClient::new(cred, path, clock, true) {\n    Ok(c) => c,\n    Err(e) => { eprintln!(\"client init failed: {e:#}\"); return Err(e); }\n}","preventionTips":["Validate the API key exists and is non-empty before constructing the client","Trim credentials read from environment/config","Test client construction at startup (fail fast) rather than at first query","Rotate and re-verify keys after any Databento account changes"],"tags":["rust","databento","api-key","client-construction"],"backgroundTag":"api-request-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"}