{"record":{"id":"640bb85a6556789d","repo":"nautechsystems/nautilus_trader","slug":"failed-to-parse-address-e","errorCode":null,"errorMessage":"Failed to parse address: {e}","messagePattern":"Failed to parse address: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/defi/pool_identifier.rs","lineNumber":193,"sourceCode":"    }\n\n    /// Returns true if this is a `PoolId` variant (V4 pools).\n    #[must_use]\n    pub fn is_pool_id(&self) -> bool {\n        matches!(self, Self::PoolId(_))\n    }\n\n    /// Converts to native Address type (V2/V3 pools only).\n    ///\n    /// Returns the underlying Address for use with alloy/ethers operations.\n    ///\n    /// # Errors\n    ///\n    /// Returns error if this is a `PoolId` variant or if parsing fails.\n    pub fn to_address(&self) -> anyhow::Result<Address> {\n        match self {\n            Self::Address(s) => Address::parse_checksummed(s.as_str(), None)\n                .map_err(|e| anyhow::anyhow!(\"Failed to parse address: {e}\")),\n            Self::PoolId(_) => anyhow::bail!(\"Cannot convert PoolId variant to Address\"),\n        }\n    }\n\n    /// Converts to native bytes array (V4 pools only).\n    ///\n    /// Returns the 32-byte pool ID for use in V4-specific operations.\n    ///\n    /// # Errors\n    ///\n    /// Returns error if this is an Address variant or if hex decoding fails.\n    pub fn to_pool_id_bytes(&self) -> anyhow::Result<[u8; 32]> {\n        match self {\n            Self::PoolId(s) => {\n                let hex_str = s.strip_prefix(\"0x\").unwrap_or(s.as_str());\n                hex::decode_array::<32>(hex_str)\n                    .map_err(|e| anyhow::anyhow!(\"Failed to decode pool ID hex: {e}\"))\n            }","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/defi/pool_identifier.rs#L175-L211","documentation":"`PoolIdentifier::to_address` converts an Address-variant identifier into an `alloy` `Address`. It errors either when called on the `PoolId` variant (a pool ID is not an address) or when the stored string fails checksummed address parsing.","triggerScenarios":"Calling `to_address()` on a `PoolIdentifier::PoolId` value, or on an Address variant whose string is not a valid checksummed 20-byte hex address (wrong length, bad checksum casing, non-hex).","commonSituations":"Code that lost track of which variant it holds after parsing mixed pool data; addresses stored lowercased without EIP-55 checksums being parsed with `parse_checksummed`.","solutions":["Match on the variant first: only call `to_address()` on `PoolIdentifier::Address`.","For PoolId values use `to_pool_id_bytes()` instead.","Store addresses in checksummed form (EIP-55) or parse with `Address::parse_checksummed(..., None)`/`Address::from_str` appropriately.","Validate the address string with `validate_hex_string` and length 40 before constructing."],"exampleFix":"// before\nlet addr = identifier.to_address()?; // panics into error for PoolId\n// after\nlet addr = match &identifier {\n    PoolIdentifier::Address(_) => identifier.to_address()?,\n    PoolIdentifier::PoolId(_) => return Err(anyhow::anyhow!(\"expected Address variant\")),\n};","handlingStrategy":"type-guard","validationCode":"fn expect_address(id: &PoolIdentifier) -> Option<&Ustr> {\n    match id { PoolIdentifier::Address(a) => Some(a), _ => None }\n}","typeGuard":"fn is_address_variant(id: &PoolIdentifier) -> bool {\n    matches!(id, PoolIdentifier::Address(_))\n}","tryCatchPattern":"match identifier.to_address() {\n    Ok(addr) => addr,\n    Err(e) if e.to_string().contains(\"PoolId\") => fallback_pool_id_path(),\n    Err(e) => return Err(e),\n}","preventionTips":["Keep variant knowledge in the type system (enum wrapper or newtype) so variant misuse cannot compile","Store addresses in EIP-55 checksummed form so parse_checksummed succeeds","Use exhaustive match on PoolIdentifier instead of blindly calling converters"],"tags":["defi","type-mismatch","variant","alloy"],"backgroundTag":"incompatible-source-type","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"}