{"record":{"id":"eda3c24230cecb1e","repo":"nautechsystems/nautilus_trader","slug":"stream-advance-error-e","errorCode":null,"errorMessage":"Stream advance error: {e}","messagePattern":"Stream advance error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/databento/src/loader.rs","lineNumber":257,"sourceCode":"    /// # Errors\n    ///\n    /// Returns an error if decoding the definition records fails.\n    pub fn read_definition_records<'a>(\n        &'a mut self,\n        filepath: &Path,\n        use_exchange_as_venue: bool,\n        decode_config: Option<&'a DatabentoDecodeConfig>,\n    ) -> anyhow::Result<impl Iterator<Item = anyhow::Result<InstrumentAny>> + 'a> {\n        let decoder = Decoder::from_zstd_file(filepath)?;\n        let mut dbn_stream = decoder.decode_stream::<InstrumentDefMsg>();\n\n        // Loop over skipped records (Ok(None)) so one unsupported class does not\n        // terminate the stream\n        Ok(std::iter::from_fn(move || {\n            loop {\n                let advance = dbn_stream\n                    .advance()\n                    .map_err(|e| anyhow::anyhow!(\"Stream advance error: {e}\"));\n                if let Err(e) = advance {\n                    return Some(Err(e));\n                }\n\n                let rec = dbn_stream.get()?;\n\n                let result: anyhow::Result<Option<InstrumentAny>> = (|| {\n                    let record = dbn::RecordRef::from(rec);\n                    let msg = record\n                        .get::<InstrumentDefMsg>()\n                        .ok_or_else(|| anyhow::anyhow!(\"Failed to decode InstrumentDefMsg\"))?;\n\n                    let raw_symbol = rec\n                        .raw_symbol()\n                        .map_err(|e| anyhow::anyhow!(\"Error decoding `raw_symbol`: {e}\"))?;\n                    let symbol = Symbol::from(raw_symbol);\n\n                    let publisher = rec","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/databento/src/loader.rs#L239-L275","documentation":"While iterating instrument definition records from a DBN zstd file, `dbn_stream.advance()` returned an Err — the underlying DBN decoder could not advance to the next record (I/O or decode failure). The adapter wraps it in anyhow and yields it from the returned iterator.","triggerScenarios":"Calling `read_definition_records` (via load_instruments) on a zstd-compressed DBN file whose stream cannot be advanced: corrupt/truncated zstd frame, invalid DBN record stream mid-file, or I/O error beneath the decoder.","commonSituations":"Partially downloaded or interrupted Databento batch download, file written with a newer DBN format version than the decoder supports, disk read errors.","solutions":["Re-download the definition file from Databento; verify integrity (file size / checksum)","Ensure the `databento-dbn` crate version is recent enough for the file's DBN schema version","Test the file decodes with the official dbn CLI/tools to isolate adapter vs data problem","Point read_definition_records at the correct file path — passing a data-schema file where a definition file is expected also breaks the stream"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// verify the file decodes and is a definition schema before iterating\nlet schema = loader.schema_from_file(&path)?;\nif schema.as_deref() != Some(\"definition\") {\n    anyhow::bail!(\"expected definition schema, got {schema:?}\");\n}","typeGuard":null,"tryCatchPattern":"let mut it = loader.read_definition_records(&path, true, None)?;\nloop {\n    match it.next() {\n        Some(Ok(inst)) => { /* use inst */ }\n        Some(Err(e)) if e.to_string().contains(\"Stream advance error\") => {\n            log::error!(\"corrupt definition file: {e}\"); break;\n        }\n        Some(Err(e)) => return Err(e),\n        None => break,\n    }\n}","preventionTips":["Re-download files whose downloads were interrupted","Keep databento-dbn current for newer DBN format versions","Verify file integrity (size/checksum) before load_instruments"],"tags":["databento","dbn","file-decode","zstd"],"backgroundTag":"file-read-failed","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"}