{"record":{"id":"f361841b3600c9a3","repo":"nautechsystems/nautilus_trader","slug":"invalid-betfair-credentials-username-provided-but","errorCode":null,"errorMessage":"Invalid Betfair credentials: username provided but password is missing","messagePattern":"Invalid Betfair credentials: username provided but password is missing","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/betfair/src/config.rs","lineNumber":75,"sourceCode":"    }\n\n    Ok(())\n}\n\nfn resolve_credential(\n    username: Option<SecretString>,\n    password: Option<SecretString>,\n    app_key: Option<SecretString>,\n) -> anyhow::Result<BetfairCredential> {\n    match BetfairCredential::resolve(\n        username.map(SecretString::into_inner),\n        password.map(SecretString::into_inner),\n        app_key.map(SecretString::into_inner),\n    ) {\n        Ok(Some(credential)) => Ok(credential),\n        Ok(None) => anyhow::bail!(\"Missing Betfair credentials in config and environment\"),\n        Err(e) => Err(match e {\n            CredentialError::MissingPassword => anyhow::anyhow!(\n                \"Invalid Betfair credentials: username provided but password is missing\",\n            ),\n            CredentialError::MissingUsername => anyhow::anyhow!(\n                \"Invalid Betfair credentials: password or app key provided but username is missing\",\n            ),\n            CredentialError::MissingAppKey => {\n                anyhow::anyhow!(\"Invalid Betfair credentials: app key is missing\")\n            }\n        }),\n    }\n}\n\nfn build_stream_config(\n    stream_host: &Option<String>,\n    stream_port: &Option<u16>,\n    stream_heartbeat_secs: Option<u64>,\n    stream_heartbeat_timeout_secs: Option<u64>,\n    stream_reconnect_delay_initial_ms: u64,","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/betfair/src/config.rs#L57-L93","documentation":"Betfair adapter credential resolution builds a Credential from config values or environment variables. If a username is present but no password, CredentialError::MissingPassword is mapped to this anyhow error in resolve_credential. The adapter refuses to start with a partially specified credential set.","triggerScenarios":"resolve_credential is called (via credential()) during BetfairDataConfig/BetfairExecutionClientConfig credential resolution when username (from config or BETFAIR_USERNAME env) is set but password is neither in config nor BETFAIR_PASSWORD env.","commonSituations":"Setting BETFAIR_USERNAME but forgetting BETFAIR_PASSWORD in the environment or .env file; providing credentials in a TOML config and omitting the password field; rotating secrets and removing the password entry.","solutions":["Set the password in the config (betfair.password) or export BETFAIR_PASSWORD before starting the node","Verify the env var name is exactly BETFAIR_PASSWORD and it is visible to the process (source the .env, check container env)","If you intend key-only auth, remove the username instead of leaving a partial credential set"],"exampleFix":"// before (shell)\nexport BETFAIR_USERNAME=myuser\n# after\nexport BETFAIR_USERNAME=myuser\nexport BETFAIR_PASSWORD=secret\nexport BETFAIR_APP_KEY=myappkey","handlingStrategy":"validation","validationCode":"if username_set && password.is_none() {\n    return Err(anyhow!(\"Betfair username provided but password is missing\"));\n}","typeGuard":"fn has_complete_creds(u: Option<&str>, p: Option<&str>, k: Option<&str>) -> bool {\n    u.is_some() == p.is_some() || k.is_some()\n}","tryCatchPattern":"match resolve_credential(cfg) {\n    Ok(c) => c,\n    Err(e) if e.to_string().contains(\"password is missing\") => {\n        eprintln!(\"set BETFAIR_PASSWORD\"); std::process::exit(1);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always set BETFAIR_USERNAME, BETFAIR_PASSWORD, and BETFAIR_APP_KEY together in your env or .env","Call config validate/credential resolution early at startup","Use a secret manager or templated config so partial credential sets are impossible"],"tags":["betfair","credentials","config","auth"],"backgroundTag":"missing-credentials","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}