{"record":{"id":"b3eb26607806c445","repo":"nautechsystems/nautilus_trader","slug":"order-book-level-index-overflow","errorCode":null,"errorMessage":"order-book level index overflow","messagePattern":"order-book level index overflow","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/http/client.rs","lineNumber":3095,"sourceCode":"            anyhow::ensure!(price.is_positive(), \"invalid non-positive {name} price\");\n            let qty_mantissa = u64::try_from(level.qty_mantissa)\n                .map_err(|_| anyhow::anyhow!(\"invalid negative {name} quantity\"))?;\n            let quantity = Quantity::from_mantissa_exponent_checked(\n                qty_mantissa,\n                snapshot.qty_exponent,\n                instrument.size_precision(),\n            )\n            .map_err(|e| anyhow::anyhow!(\"invalid {name} quantity: {e}\"))?;\n            anyhow::ensure!(\n                quantity.is_positive(),\n                \"invalid non-positive {name} quantity\"\n            );\n            let order = BookOrder::new(\n                side,\n                price,\n                quantity,\n                u64::try_from(order_id)\n                    .map_err(|_| anyhow::anyhow!(\"order-book level index overflow\"))?,\n            );\n            book.add(order, 0, sequence, ts_event);\n            Ok(())\n        };\n\n        for (index, level) in snapshot.bids.iter().enumerate() {\n            add_level(level, OrderSide::Buy, index, \"bid\")?;\n        }\n        let bid_count = snapshot.bids.len();\n        for (index, level) in snapshot.asks.iter().enumerate() {\n            let order_id = bid_count\n                .checked_add(index)\n                .ok_or_else(|| anyhow::anyhow!(\"order-book level index overflow\"))?;\n            add_level(level, OrderSide::Sell, order_id, \"ask\")?;\n        }\n        Ok(book)\n    }\n","sourceCodeStart":3077,"sourceCodeEnd":3113,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/http/client.rs#L3077-L3113","documentation":"Thrown when converting the per-level synthetic order ID (a `usize` level index) into the `u64` order ID required by `BookOrder::new` fails. On 64-bit platforms this is effectively unreachable; it guards a `usize`→`u64` narrowing that only fails on exotic targets.","triggerScenarios":"Calling `request_book_snapshot` on a platform where `usize` exceeds 64 bits (e.g. 128-bit `usize`) and the level index cannot fit in `u64`.","commonSituations":"Building/running on non-64-bit or unusual pointer-width targets; practically never seen on standard x86_64/aarch64 builds.","solutions":["Run on a standard 64-bit platform where `usize == u64`.","If targeting an exotic architecture, build with a 64-bit `usize` target.","This is an internal invariant guard — file an issue if it reproduces on a mainstream target."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match client.request_book_snapshot(id, depth).await {\n    Ok(book) => book,\n    Err(e) if e.to_string().contains(\"level index overflow\") => {\n        log::error!(\"usize/u64 width mismatch on this target\");\n        Err(e)\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Target standard 64-bit platforms (x86_64, aarch64) where usize == u64.","Treat this as an internal invariant failure and file an issue if it reproduces."],"tags":["orderbook","binance","overflow","internal"],"backgroundTag":"value-out-of-range","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"}