{"record":{"id":"33f1a606857cae9f","repo":"nautechsystems/nautilus_trader","slug":"private-key-env-not-found-in-config-or-environme","errorCode":null,"errorMessage":"{private_key_env} not found in config or environment","messagePattern":"(.+?) not found in config or environment","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"critical","filePath":"crates/adapters/dydx/src/execution/mod.rs","lineNumber":286,"sourceCode":"    }\n\n    fn resolve_private_key(config: &DydxAdapterConfig) -> anyhow::Result<String> {\n        let (private_key_env, _) = credential_env_vars(config.network);\n\n        if let Some(ref pk) = config.private_key\n            && !pk.expose_secret().trim().is_empty()\n        {\n            return Ok(pk.expose_secret().to_owned());\n        }\n\n        if let Some(pk) = std::env::var(private_key_env)\n            .ok()\n            .filter(|s| !s.trim().is_empty())\n        {\n            return Ok(pk);\n        }\n\n        anyhow::bail!(\"{private_key_env} not found in config or environment\")\n    }\n\n    fn register_order_context(&self, client_id_u32: u32, context: OrderContext) {\n        self.order_contexts.insert(client_id_u32, context);\n    }\n\n    fn get_order_context(&self, client_id_u32: u32) -> Option<OrderContext> {\n        self.order_contexts\n            .get(&client_id_u32)\n            .map(|r| r.value().clone())\n    }\n\n    fn get_chain_id(&self) -> ChainId {\n        self.config.get_chain_id()\n    }\n\n    fn spawn_ws_stream_handler(\n        &self,","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/dydx/src/execution/mod.rs#L268-L304","documentation":"The dYdX execution client needs the wallet's Ethereum private key to sign orders. resolve_private_key looks for the value in the client config first, then in the environment variable named by private_key_env; if neither yields a non-empty string it bails naming the missing env var.","triggerScenarios":"Creating/connecting the dYdX execution client when the private key is absent from the config and the referenced environment variable is unset or contains only whitespace.","commonSituations":"Running in an environment where the .env file or secret injection was not loaded; misnaming the env var (e.g. DYDX_PRIVATE_KEY vs DYDX_ETHEREUM_PRIVATE_KEY); empty-string key in config after templating.","solutions":["Set the expected environment variable (e.g. export DYDX_PRIVATE_KEY=0x...) before starting the process","Pass the private key via the client config's private_key field","Verify the env var name in your config matches what is actually exported; check .env loading","Use a secrets manager/injection so the key is present in CI or containers"],"exampleFix":"// before (shell)\n./start-strategy  # DYDX_PRIVATE_KEY unset\n// after (shell)\nexport DYDX_PRIVATE_KEY=0xabc123... && ./start-strategy","handlingStrategy":"validation","validationCode":"fn ensure_private_key_available(env_var: &str, config_key: Option<&str>) -> Result<(), String> {\n    if config_key.map_or(false, |k| !k.trim().is_empty()) {\n        return Ok(());\n    }\n    match std::env::var(env_var) {\n        Ok(v) if !v.trim().is_empty() => Ok(()),\n        _ => Err(format!(\"{env_var} not found in config or environment\")),\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify the private key env var is exported before process start (especially in CI/containers)","Keep the env var name consistent between config and deployment scripts","Load .env files or secret injection early in application startup","Never commit keys; use a secrets manager"],"tags":["rust","dydx-exchange","private-key","environment-variable","configuration"],"backgroundTag":"missing-env-var","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"}