{"record":{"id":"5f61523ba2a346ca","repo":"nautechsystems/nautilus_trader","slug":"failed-to-decode-instrumentdefmsg","errorCode":null,"errorMessage":"Failed to decode InstrumentDefMsg","messagePattern":"Failed to decode InstrumentDefMsg","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/databento/src/loader.rs","lineNumber":268,"sourceCode":"\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\n                        .hd\n                        .publisher()\n                        .map_err(|e| anyhow::anyhow!(\"Invalid `publisher` for record: {e}\"))?;\n                    let venue = match publisher {\n                        Publisher::GlbxMdp3Glbx if use_exchange_as_venue => {\n                            let exchange = rec.exchange().map_err(|e| {\n                                anyhow::anyhow!(\"Missing `exchange` for record: {e}\")\n                            })?;\n                            let venue = Venue::from_code(exchange).map_err(|e| {\n                                anyhow::anyhow!(\"Venue not found for exchange {exchange}: {e}\")\n                            })?;","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/databento/src/loader.rs#L250-L286","documentation":"Inside the definition-record iterator, a record was advanced to successfully but `record.get::<InstrumentDefMsg>()` returned None — the record's rtype does not correspond to an InstrumentDefMsg, so it cannot be interpreted as an instrument definition.","triggerScenarios":"`read_definition_records` is pointed at a DBN file whose schema is not `definition` (e.g. trades/ohlcv/mbo data), or the file mixes record types so a non-definition record is encountered where an InstrumentDefMsg is required.","commonSituations":"Passing a data file to load_instruments instead of a definition-schema file, renamed/mislabeled files in a batch download, mixing multiple schemas into one stream.","solutions":["Verify the file is a `definition` schema export (check via loader.schema_from_file or the Databento download parameters) and point load_instruments at the correct file","Re-download with schema=definition for the same dataset/range if the wrong file was produced","Filter/skip non-definition records before this iterator if your pipeline intentionally mixes schemas"],"exampleFix":"// before\nlet instruments = loader.load_instruments(&trades_file_path, ...)?; // wrong schema\n// after\nassert_eq!(loader.schema_from_file(&path)?, Some(\"definition\".to_string()));\nlet instruments = loader.load_instruments(&definition_path, ...)?;","handlingStrategy":"validation","validationCode":"// confirm the file is a definition schema before load_instruments\nlet schema = loader.schema_from_file(&path)?;\nassert_eq!(schema.as_deref(), Some(\"definition\"), \"wrong schema for load_instruments\");","typeGuard":null,"tryCatchPattern":"match loader.load_instruments(&path, true, None) {\n    Ok(m) => m,\n    Err(e) if e.to_string().contains(\"Failed to decode InstrumentDefMsg\") => {\n        anyhow::bail!(\"{path:?} is not a definition-schema DBN file\")\n    }\n    other => other,\n}","preventionTips":["Check schema via loader.schema_from_file before loading","Keep definition files clearly named and separate from data files","Only point load_instruments at files downloaded with schema=definition"],"tags":["databento","dbn","schema-mismatch","instrument-definitions"],"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"}