{"record":{"id":"27a426bd4f9ea9fd","repo":"nautechsystems/nautilus_trader","slug":"invalid-hex-u64-e","errorCode":null,"errorMessage":"Invalid hex u64: {e}","messagePattern":"Invalid hex u64: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/rpc/log.rs","lineNumber":40,"sourceCode":"use nautilus_model::defi::rpc::RpcLog;\n\n/// Decode hex string (with or without 0x prefix) to bytes.\n///\n/// # Errors\n///\n/// Returns an error if the hex string is invalid.\npub fn decode_hex(hex: &str) -> anyhow::Result<Vec<u8>> {\n    hex::decode(hex.trim_start_matches(\"0x\")).map_err(|e| anyhow::anyhow!(\"Invalid hex: {e}\"))\n}\n\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> {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/rpc/log.rs#L22-L58","documentation":"This error means a hex-encoded string (e.g. from an Ethereum RPC response) failed to parse as a u64. The helper strips an optional '0x' prefix and calls u64::from_str_radix base 16; any character that is not a valid hex digit, an empty string, or a value exceeding u64 range produces this error. It is thrown by parse_hex_u64, typically via extract_block_number.","triggerScenarios":"Calling parse_hex_u64 with a string like \"\" (empty after stripping 0x), containing non-hex characters (e.g. \"0x12g4\"), whitespace embedded inside, or a number above u64::MAX (e.g. 20+ hex digits).","commonSituations":"Malformed or placeholder block-number fields from custom/nonstandard RPC nodes (some return \"pending\" or null-adjacent values), accidental double-encoding, or passing a full 32-byte topic hex where a short quantity hex was expected.","solutions":["Inspect the offending string and confirm it is a valid hex quantity (optional 0x prefix, digits 0-9a-fA-F only, within u64 range).","If the upstream field can be non-numeric (e.g. \"pending\"), check for that case before calling parse_hex_u64.","Trim/normalize the input (trim whitespace, strip 0x) and validate with a regex before parsing.","Increase the target type only if the value genuinely exceeds u64 range (use u128 or a big-int type)."],"exampleFix":"// before\nlet n = parse_hex_u64(log.block_number.as_deref().unwrap_or(\"\"))?;\n// after\nlet hex = log.block_number.as_deref().filter(|s| s.chars().all(|c| c.is_ascii_hexdigit()))\n    .ok_or_else(|| anyhow::anyhow!(\"Missing block number\"))?;\nlet n = parse_hex_u64(hex)?;","handlingStrategy":"validation","validationCode":"fn is_hex_u64(s: &str) -> bool {\n    let t = s.trim_start_matches(\"0x\");\n    !t.is_empty() && t.len() <= 16 && t.chars().all(|c| c.is_ascii_hexdigit())\n}","typeGuard":"fn looks_like_hex_quantity(s: &str) -> bool {\n    let t = s.trim_start_matches(\"0x\");\n    !t.is_empty() && t.chars().all(|c| c.is_ascii_hexdigit())\n}","tryCatchPattern":"match parse_hex_u64(hex) {\n    Ok(v) => v,\n    Err(e) => { log::warn!(\"bad hex {hex}: {e}\"); return Err(e); }\n}","preventionTips":["Validate hex strings with a regex before parsing.","Check for non-numeric placeholders like \"pending\" from RPC responses.","Remember u64 hex maxes at 16 digits.","Trim whitespace and normalize the 0x prefix."],"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-14T00:17:10.932Z"}