{"record":{"id":"ae543a7ebf2e7a78","repo":"nautechsystems/nautilus_trader","slug":"invalid-statmsg","errorCode":null,"errorMessage":"Invalid `StatMsg`","messagePattern":"Invalid `StatMsg`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/databento/src/loader.rs","lineNumber":913,"sourceCode":"            None\n        };\n        let mut dbn_stream = decoder.decode_stream::<T>();\n        let fixed_instrument_id = instrument_id.is_some();\n        let mut fixed_price_precision = price_precision;\n\n        // Loop over skipped records so one unsupported stat_type does not terminate\n        // the stream; precheck before precision resolution.\n        Ok(std::iter::from_fn(move || {\n            loop {\n                if let Err(e) = dbn_stream.advance() {\n                    return Some(Err(e.into()));\n                }\n\n                let rec = dbn_stream.get()?;\n                let record = dbn::RecordRef::from(rec);\n                let msg = match record.get::<dbn::StatMsg>() {\n                    Some(m) => m,\n                    None => return Some(Err(anyhow::anyhow!(\"Invalid `StatMsg`\"))),\n                };\n\n                if !is_supported_stat_type(msg.stat_type) {\n                    log::warn!(\"Skipping unsupported `stat_type` {}\", msg.stat_type);\n                    continue;\n                }\n\n                let instrument_id = match self.resolve_record_instrument_id(\n                    &record,\n                    instrument_id,\n                    &mut metadata_cache,\n                ) {\n                    Ok(id) => id,\n                    Err(e) => return Some(Err(e)),\n                };\n                let resolved_precision = match self.resolve_stream_price_precision(\n                    &instrument_id,\n                    fixed_instrument_id,","sourceCodeStart":895,"sourceCodeEnd":931,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/databento/src/loader.rs#L895-L931","documentation":"`read_statistics_records` expects each stream record to decode as `dbn::StatMsg`. If `record.get::<StatMsg>()` returns None the loader returns `Invalid \\`StatMsg\\``, indicating the stream holds records of a different type than statistics.","triggerScenarios":"Calling `read_statistics_records` on a DBN file/stream not produced with the `statistics` schema, or a stream where a non-stat record appears (mixed or mislabeled export).","commonSituations":"Downloading `stats`/statistics data but loading the wrong file; concatenated exports of several schemas.","solutions":["Download with the statistics schema so records are StatMsg","Confirm the file path passed to `read_statistics_records` points at the statistics export","Process each schema's file separately instead of concatenating DBN files","Inspect the record rtype/dbn header to confirm it is `statistics` before loading"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"assert_eq!(request.schema, \"stats\", \"read_statistics_records requires the statistics schema\");","typeGuard":"fn is_stat_record(rec: &dbn::RecordRef) -> bool {\n    rec.get::<dbn::StatMsg>().is_some()\n}","tryCatchPattern":"for item in loader.read_statistics_records(file, instrument_id) {\n    match item {\n        Ok(stat) => handle(stat),\n        Err(e) if e.to_string().contains(\"Invalid `StatMsg`\") => {\n            log::error!(\"stream is not statistics data: {e}\");\n            break;\n        }\n        Err(e) => return Err(e),\n    }\n}","preventionTips":["Download statistics data with the correct schema parameter","Tag exported files with their schema to avoid misrouting","Inspect the DBN header rtype before loading"],"tags":["databento","record-type-mismatch"],"backgroundTag":"incompatible-source-type","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"}