{"record":{"id":"8397019b3674a5d8","repo":"nautechsystems/nautilus_trader","slug":"invalid-hex-u32-e","errorCode":null,"errorMessage":"Invalid hex u32: {e}","messagePattern":"Invalid hex u32: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/rpc/log.rs","lineNumber":50,"sourceCode":"\n/// Parse hex string to u64.\n///\n/// # Errors\n///\n/// Returns an error if the hex string cannot be parsed as u64.\npub fn parse_hex_u64(hex: &str) -> anyhow::Result<u64> {\n    u64::from_str_radix(hex.trim_start_matches(\"0x\"), 16)\n        .map_err(|e| anyhow::anyhow!(\"Invalid hex u64: {e}\"))\n}\n\n/// Parse hex string to u32.\n///\n/// # Errors\n///\n/// Returns an error if the hex string cannot be parsed as u32.\npub fn parse_hex_u32(hex: &str) -> anyhow::Result<u32> {\n    u32::from_str_radix(hex.trim_start_matches(\"0x\"), 16)\n        .map_err(|e| anyhow::anyhow!(\"Invalid hex u32: {e}\"))\n}\n\n/// Extract block number from RPC log.\n///\n/// # Errors\n///\n/// Returns an error if the block number is missing or cannot be parsed.\npub fn extract_block_number(log: &RpcLog) -> anyhow::Result<u64> {\n    let hex = log\n        .block_number\n        .as_ref()\n        .ok_or_else(|| anyhow::anyhow!(\"Missing block number\"))?;\n    parse_hex_u64(hex)\n}\n\n/// Extract transaction hash from RPC log.\n///\n/// # Errors","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/rpc/log.rs#L32-L68","documentation":"This error means a hex-encoded string failed to parse as a u32. Like parse_hex_u64, it strips the '0x' prefix and parses base 16; invalid hex characters, an empty string, or values above u32::MAX (more than 8 hex digits) cause the failure. Thrown by parse_hex_u32, typically via extract_transaction_index and extract_log_index.","triggerScenarios":"Calling parse_hex_u32 with \"0x\", empty strings, non-hex characters, or values above 0xffffffff (e.g. an over-long quantity hex from a malformed RPC payload).","commonSituations":"RPC nodes returning padded or malformed index fields, passing a 32-byte topic string (64 hex chars) into a u32 parser, or feeding hash strings into index parsers by mistake.","solutions":["Verify the string is a valid hex quantity with at most 8 significant digits (0 to 0xffffffff).","If the value may exceed u32 (e.g. some chains use wider indices), parse as u64 instead.","Check you are not accidentally passing a hash or topic hex into this parser.","Trim whitespace and validate with a regex before calling."],"exampleFix":"// before\nlet idx = parse_hex_u32(some_topic_hex)?;\n// after\nlet idx = u64::from_str_radix(some_topic_hex.trim_start_matches(\"0x\"), 16)? as u32;","handlingStrategy":"validation","validationCode":"fn is_hex_u32(s: &str) -> bool {\n    let t = s.trim_start_matches(\"0x\");\n    !t.is_empty() && t.len() <= 8 && t.chars().all(|c| c.is_ascii_hexdigit())\n}","typeGuard":"fn looks_like_hex_u32(s: &str) -> bool {\n    matches!(u32::from_str_radix(s.trim_start_matches(\"0x\"), 16), Ok(_))\n}","tryCatchPattern":"match parse_hex_u32(hex) {\n    Ok(v) => v,\n    Err(e) => { log::warn!(\"bad hex u32 {hex}: {e}\"); 0 }\n}","preventionTips":["Ensure values fit in 8 hex digits for u32.","Do not pass topic (64-digit) hex into u32 parsers.","Confirm the RPC field is an index, not a hash.","Trim and strip 0x before validating."],"tags":["parsing","hex","blockchain","rpc"],"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"}