{"record":{"id":"174a8a87929819b9","repo":"nautechsystems/nautilus_trader","slug":"password-not-set-nor-available-in-env-tws-password","errorCode":null,"errorMessage":"password not set nor available in env TWS_PASSWORD","messagePattern":"password not set nor available in env TWS_PASSWORD","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"critical","filePath":"crates/adapters/interactive_brokers/src/gateway/dockerized.rs","lineNumber":186,"sourceCode":"    /// * `config` - Configuration for the gateway\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if:\n    /// - Username or password is not provided and not available in environment variables\n    /// - Docker client creation fails\n    pub fn new(mut config: DockerizedIBGatewayConfig) -> anyhow::Result<Self> {\n        let username = config\n            .username\n            .take()\n            .or_else(|| std::env::var(\"TWS_USERNAME\").ok().map(SecretString::from))\n            .ok_or_else(|| anyhow::anyhow!(\"username not set nor available in env TWS_USERNAME\"))?;\n\n        let password = config\n            .password\n            .take()\n            .or_else(|| std::env::var(\"TWS_PASSWORD\").ok().map(SecretString::from))\n            .ok_or_else(|| anyhow::anyhow!(\"password not set nor available in env TWS_PASSWORD\"))?;\n\n        // Connect to Docker\n        let docker = Docker::connect_with_local_defaults().context(\n            \"Failed to connect to the local Docker daemon. Ensure Docker is running and the local Docker socket is available\",\n        )?;\n\n        // Determine port based on trading mode\n        let mode_str = match config.trading_mode {\n            crate::config::TradingMode::Paper => \"Paper\",\n            crate::config::TradingMode::Live => \"Live\",\n        };\n        let port = Self::host_port_for_mode(config.trading_mode);\n\n        // Generate container name\n        let container_name = format!(\"{}-{}\", Self::CONTAINER_NAME, mode_str).to_lowercase();\n\n        Ok(Self {\n            config,","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/gateway/dockerized.rs#L168-L204","documentation":"DockerizedIBGateway::new requires the IB Gateway password, taken from DockerizedIBGatewayConfig.password with fallback to the TWS_PASSWORD environment variable. If neither is set, construction fails with this error so no gateway container is ever started without credentials.","triggerScenarios":"Calling DockerizedIBGateway::new with config.password == None while TWS_PASSWORD is not present in the process environment.","commonSituations":"Setting TWS_USERNAME but forgetting TWS_PASSWORD; running in CI where only one secret was injected; password defined in a secret manager not wired into the process environment.","solutions":["Set TWS_PASSWORD in the environment before starting the process.","Set `password` explicitly on DockerizedIBGatewayConfig.","Inject the password via your secret manager / CI secrets into the process environment.","Double-check both TWS_USERNAME and TWS_PASSWORD are present — construction requires both."],"exampleFix":"// before\nlet gateway = DockerizedIBGateway::new(DockerizedIBGatewayConfig::default())?;\n// after\nlet gateway = DockerizedIBGateway::new(DockerizedIBGatewayConfig {\n    password: Some(SecretString::from(\"my_password\")),\n    ..Default::default()\n})?;","handlingStrategy":"validation","validationCode":"if std::env::var(\"TWS_PASSWORD\").is_err() {\n    panic!(\"TWS_PASSWORD must be set (or pass password in DockerizedIBGatewayConfig) before starting the gateway\");\n}","typeGuard":null,"tryCatchPattern":"match DockerizedIBGateway::new(config) {\n    Ok(gw) => (),\n    Err(e) if e.to_string().contains(\"password not set nor available in env TWS_PASSWORD\") => {\n        return Err(anyhow!(\"gateway credentials missing: set TWS_PASSWORD or config.password\"));\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Inject both TWS_USERNAME and TWS_PASSWORD together from your secret store","Never rely on interactive shell environment; set secrets in the deployment manifest","Check credential presence in a startup smoke test before live trading"],"tags":["credentials","env-var","docker","gateway"],"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"}