{"record":{"id":"2f49581713274625","repo":"nautechsystems/nautilus_trader","slug":"invalid-address-e","errorCode":null,"errorMessage":"Invalid address: {e}","messagePattern":"Invalid address: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/defi/pool_identifier.rs","lineNumber":79,"sourceCode":"    /// - String doesn't start with \"0x\"\n    /// - Length is neither 42 nor 66 characters\n    /// - Contains invalid hex characters\n    /// - Address checksum validation fails (for Address variant)\n    pub fn new_checked<T: AsRef<str>>(value: T) -> anyhow::Result<Self> {\n        let value = value.as_ref();\n\n        if !value.starts_with(\"0x\") {\n            anyhow::bail!(\"Pool identifier must start with '0x', was: {value}\");\n        }\n\n        match value.len() {\n            42 => {\n                validate_hex_string(value)?;\n\n                // Parse without strict checksum validation, then normalize to checksummed format\n                let addr = value\n                    .parse::<Address>()\n                    .map_err(|e| anyhow::anyhow!(\"Invalid address: {e}\"))?;\n\n                // Store the checksummed version\n                Ok(Self::Address(Ustr::from(addr.to_checksum(None).as_str())))\n            }\n            66 => {\n                // PoolId variant (32 bytes)\n                validate_hex_string(value)?;\n\n                // Store lowercase version for consistency\n                Ok(Self::PoolId(Ustr::from(&value.to_lowercase())))\n            }\n            len => {\n                anyhow::bail!(\n                    \"Pool identifier must be 42 chars (address) or 66 chars (pool ID), was {len} chars: {value}\"\n                )\n            }\n        }\n    }","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/defi/pool_identifier.rs#L61-L97","documentation":"`PoolIdentifier::new_checked` validates identifier strings, dispatching on a length-prefix (42 hex chars = EVM address, 66 = PoolId). For the 42-char case it parses the value as an EVM `Address`; if the hex string is not a valid address (bad hex, wrong length after validation gaps, parse failure), the error is wrapped as 'Invalid address: {e}'.","triggerScenarios":"Calling `new_checked` with a 42-character string that fails `Address` parsing — e.g. non-hex characters, '0x' prefix issues, or a value that passed `validate_hex_string` but isn't a canonical 20-byte address.","commonSituations":"Copy-pasting truncated or malformed contract addresses; addresses with mixed casing failing parse pre-checks; user-supplied pool/address config containing typos; ingesting identifiers from an external source with encoding drift.","solutions":["Confirm the string is exactly `0x` + 40 hex characters before calling `new_checked`.","Validate the address (e.g. regex `^0x[0-9a-fA-F]{40}$` or ethers/alloy parsing) upstream and show a clear user-facing message.","Fix the data source emitting the identifier (truncation, missing 0x, wrong encoding).","Use the parse error detail (`{e}`) to pinpoint which character/length failed and correct the input."],"exampleFix":"// before\nlet id = PoolIdentifier::new_checked(user_input)?; // opaque error on typos\n// after\nfn is_evm_address(s: &str) -> bool {\n    s.len() == 42 && s.starts_with(\"0x\") && s[2..].chars().all(|c| c.is_ascii_hexdigit())\n}\nif !is_evm_address(user_input) {\n    anyhow::bail!(\"'{}' is not a valid 0x + 40-hex EVM address\", user_input);\n}\nlet id = PoolIdentifier::new_checked(user_input)?;","handlingStrategy":"validation","validationCode":"fn valid_evm_address(s: &str) -> bool {\n    s.len() == 42 && s.starts_with(\"0x\") && s[2..].chars().all(|c| c.is_ascii_hexdigit())\n}","typeGuard":null,"tryCatchPattern":"match PoolIdentifier::new_checked(value) {\n    Ok(id) => id,\n    Err(e) if e.to_string().starts_with(\"Invalid address:\") => bail!(\"'{value}' is not a valid EVM address: {e}\"),\n    Err(e) => return Err(e),\n}","preventionTips":["Validate addresses at input boundaries (UI/config) with a regex before passing to the library","Use checksummed addresses consistently when storing/passing identifiers","Sanitize data imported from external sources (strip whitespace, ensure 0x prefix)"],"tags":["evm","address","validation"],"backgroundTag":"invalid-argument-format","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"}