{"record":{"id":"c3a30e865d607ca8","repo":"nautechsystems/nautilus_trader","slug":"slice-length-10","errorCode":null,"errorMessage":"Slice length != 10","messagePattern":"Slice length != 10","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/ffi/data/depth.rs","lineNumber":108,"sourceCode":"    asks_ptr: *const BookOrderFfi,\n    bid_counts_ptr: *const u32,\n    ask_counts_ptr: *const u32,\n    flags: u8,\n    sequence: u64,\n    ts_event: UnixNanos,\n    ts_init: UnixNanos,\n) -> OrderBookDepth10Ffi {\n    abort_on_panic(|| {\n        // SAFETY: Null checks run before slice construction. The caller still\n        // guarantees each pointer refers to `DEPTH10_LEN` initialized elements.\n        assert!(!bids_ptr.is_null());\n        assert!(!asks_ptr.is_null());\n        assert!(!bid_counts_ptr.is_null());\n        assert!(!ask_counts_ptr.is_null());\n\n        let bids_slice = unsafe { std::slice::from_raw_parts(bids_ptr, DEPTH10_LEN) };\n        let asks_slice = unsafe { std::slice::from_raw_parts(asks_ptr, DEPTH10_LEN) };\n        let bids: [BookOrderFfi; DEPTH10_LEN] = bids_slice.try_into().expect(\"Slice length != 10\");\n        let asks: [BookOrderFfi; DEPTH10_LEN] = asks_slice.try_into().expect(\"Slice length != 10\");\n\n        let bid_counts_slice = unsafe { std::slice::from_raw_parts(bid_counts_ptr, DEPTH10_LEN) };\n        let ask_counts_slice = unsafe { std::slice::from_raw_parts(ask_counts_ptr, DEPTH10_LEN) };\n        let bid_counts: [u32; DEPTH10_LEN] =\n            bid_counts_slice.try_into().expect(\"Slice length != 10\");\n        let ask_counts: [u32; DEPTH10_LEN] =\n            ask_counts_slice.try_into().expect(\"Slice length != 10\");\n\n        OrderBookDepth10::new(\n            instrument_id,\n            bids.map(Into::into),\n            asks.map(Into::into),\n            bid_counts,\n            ask_counts,\n            flags,\n            sequence,\n            ts_event,","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/data/depth.rs#L90-L126","documentation":"orderbook_depth10_new builds fixed-size [BookOrderFfi; 10] arrays from raw pointers by converting a slice of DEPTH10_LEN via try_into().expect(\"Slice length != 10\"). Although the slice is created with from_raw_parts(..., DEPTH10_LEN) and therefore should always be length 10, if the conversion is invoked with a differently sized buffer/layout mismatch this expect panics. It is an internal invariant check guarding the fixed-depth-10 FFI contract.","triggerScenarios":"Calling orderbook_depth10_new with bid/ask pointer buffers that are not exactly 10 contiguous BookOrderFfi elements (undersized allocations, wrong struct packing, or mismatched layout between caller and library).","commonSituations":"Custom Cython/ctypes bindings that allocate arrays with the wrong element size or count, ABI drift after BookOrderFfi changed, or adapter code reusing depth buffers sized for other depth levels.","solutions":["Allocate exactly 10 elements of the exact BookOrderFfi layout for bids and asks before the call.","Rebuild bindings against the current model crate so BookOrderFfi size/alignment match on both sides.","Check for compiler warnings about type layout changes after upgrading nautilus; pin compatible versions.","If you maintain the FFI wrapper, assert the ctypes.sizeof/length equals the Rust-side size and 10 elements before calling."],"exampleFix":"// before (ctypes)\nbids = (BookOrderFfi * depth) (*orders)  # depth may not be 10\n// after\nassert depth == 10, \"Depth10 requires exactly 10 orders per side\"\nbids = (BookOrderFfi * 10)(*orders[:10])","handlingStrategy":"validation","validationCode":"# Python caller\nassert len(bids) == 10 and len(asks) == 10, \"Depth10 needs exactly 10 orders per side\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Allocate fixed [T; 10] / (T * 10) buffers for both sides.","Keep struct layouts (BookOrderFfi) identical on both sides of the FFI boundary.","Upgrade caller bindings and Rust extension together."],"tags":["ffi","panic","array-length","orderbook","rust"],"backgroundTag":"shape-mismatch","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"}