{"record":{"id":"ac33cd312151ab00","repo":"nautechsystems/nautilus_trader","slug":"invalid-levels","errorCode":null,"errorMessage":"Invalid levels: {}","messagePattern":"Invalid levels: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/tardis/src/csv/stream.rs","lineNumber":1528,"sourceCode":"            return Some(Ok(chunk));\n        }\n\n        self.buffer.clear();\n        let mut records_read = 0;\n\n        while records_read < self.chunk_size {\n            match self.reader.read_record(&mut self.record) {\n                Ok(true) => {\n                    let result = match self.levels {\n                        5 => self\n                            .record\n                            .deserialize::<TardisOrderBookSnapshot5Record>(None)\n                            .map(|data| self.process_snapshot5(&data)),\n                        25 => self\n                            .record\n                            .deserialize::<TardisOrderBookSnapshot25Record>(None)\n                            .map(|data| self.process_snapshot25(&data)),\n                        _ => return Some(Err(anyhow::anyhow!(\"Invalid levels: {}\", self.levels))),\n                    };\n\n                    match result {\n                        Ok(depth) => {\n                            self.buffer.push(depth);\n                            records_read += 1;\n                            self.records_processed += 1;\n\n                            if let Some(limit) = self.limit\n                                && self.records_processed >= limit\n                            {\n                                break;\n                            }\n                        }\n                        Err(e) => {\n                            return Some(Err(anyhow::anyhow!(\"Failed to deserialize record: {e}\")));\n                        }\n                    }","sourceCodeStart":1510,"sourceCodeEnd":1546,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/tardis/src/csv/stream.rs#L1510-L1546","documentation":"Depth10StreamIterator::next returns this error when self.levels holds a value other than 5 or 25 inside the iterator loop. In normal use Depth10StreamIterator::new already guarantees levels is 5 or 25 via anyhow::ensure!, so reaching this arm indicates the iterator was constructed directly (bypassing new) or an internal invariant was broken.","triggerScenarios":"Constructing Depth10StreamIterator with a struct literal instead of new() and a levels field outside {5, 25}; any code path that mutates levels after construction; the match's fall-through arm at line 1528.","commonSituations":"Internal maintenance or test code instantiating the private iterator directly; refactoring that moved or removed the constructor check.","solutions":["Always construct the iterator via Depth10StreamIterator::new (or the public stream_order_book_depth10) which validates levels.","If you instantiate directly, ensure levels == 5 || levels == 25 before use.","Do not mutate levels after construction; it is a fixed stream property.","If you hit this in library code, file a bug — it signals an internal invariant violation."],"exampleFix":"// before: direct struct construction bypassing validation\nlet it = Depth10StreamIterator { levels: 10, .. };\n// after: go through new(), which ensures levels is 5 or 25\nlet it = Depth10StreamIterator::new(path, chunk, 10, None, None, None, None)?;\n// -> returns \"Invalid levels: 10. Must be 5 or 25.\" early, before streaming","handlingStrategy":"type-guard","validationCode":"// library users never reach this arm; guard construction path instead\nlet levels = if file_is_snapshot25 { 25 } else { 5 };\nanymore::ensure!(levels == 5 || levels == 25);","typeGuard":"fn is_supported_levels(levels: u8) -> bool { levels == 5 || levels == 25 }","tryCatchPattern":"// the iterator only errors here if built without new(); always use:\nlet it = stream_order_book_depth10(path, chunk, levels, None, None, None, None)?;\n// which validates levels up front","preventionTips":["Never construct Depth10StreamIterator directly; use the public stream function.","Do not mutate the levels field after construction.","Keep the constructor's anyhow::ensure! check when refactoring.","Treat this error in library code as a bug report trigger."],"tags":["validation","invariant","tardis","orderbook"],"backgroundTag":"invalid-argument-value","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"}