{"record":{"id":"797b1d1d4c9434a4","repo":"nautechsystems/nautilus_trader","slug":"invalid-instrumentid-for-instrument-id","errorCode":null,"errorMessage":"Invalid `InstrumentId` for 'instrument_id'","messagePattern":"Invalid `InstrumentId` for 'instrument_id'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/data/mod.rs","lineNumber":899,"sourceCode":"    /// Returns the optional catalog path identifier (can contain subdirs, e.g. `\"venue//symbol\"`).\n    #[must_use]\n    pub fn identifier(&self) -> Option<&str> {\n        self.identifier.as_deref()\n    }\n\n    /// Returns an [`Option<InstrumentId>`] parsed from the metadata.\n    ///\n    /// # Panics\n    ///\n    /// This function panics if:\n    /// - The `instrument_id` value contained in the metadata is invalid.\n    #[must_use]\n    pub fn instrument_id(&self) -> Option<InstrumentId> {\n        let metadata = self.metadata.as_ref()?;\n        let instrument_id = metadata.get_str(\"instrument_id\")?;\n        Some(\n            InstrumentId::from_str(instrument_id)\n                .expect(\"Invalid `InstrumentId` for 'instrument_id'\"),\n        )\n    }\n\n    /// Returns an [`Option<Venue>`] parsed from the metadata.\n    ///\n    /// # Panics\n    ///\n    /// This function panics if:\n    /// - The `venue` value contained in the metadata is invalid.\n    #[must_use]\n    pub fn venue(&self) -> Option<Venue> {\n        let metadata = self.metadata.as_ref()?;\n        let venue_str = metadata.get_str(\"venue\")?;\n        Some(Venue::from(venue_str))\n    }\n\n    /// Returns an [`Option<UnixNanos>`] parsed from the metadata `start` field.\n    ///","sourceCodeStart":881,"sourceCodeEnd":917,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/data/mod.rs#L881-L917","documentation":"In `Data::instrument_id`, the metadata dict's \"instrument_id\" string is parsed into an `InstrumentId`, and parsing failure panics with \"Invalid `InstrumentId` for 'instrument_id'\". The library treats metadata as already validated, so a malformed ID (missing venue, bad characters) is a hard error. Note the method returns `Option` when the key is absent — this panic only fires when the key exists but the value is unparseable.","triggerScenarios":"Creating a `Data`/custom data payload whose metadata contains `instrument_id` as a string that is not a valid `InstrumentId` (e.g. \"AAPL\" without a venue, \"AAPL@\" or extra whitespace), then calling `.instrument_id()`.","commonSituations":"Hand-written metadata in custom data classes from Python; config files or adapters writing IDs in a non-canonical format; old persisted data written by a version with different ID formatting.","solutions":["Fix the metadata value to a canonical InstrumentId string like \"AAPL.NYSE\" or \"BTCUSDT.BINANCE\"","Validate the string with `InstrumentId::from_str` in a controlled context before storing it in metadata","If migrating old data, re-write metadata with the correct format"],"exampleFix":"// before\nmetadata[\"instrument_id\"] = \"AAPL\"  // missing venue\n// after\nmetadata[\"instrument_id\"] = \"AAPL.NYSE\"  // valid InstrumentId format SYMBOL.VENUE","handlingStrategy":"validation","validationCode":"from nautilus_trader.model.identifiers import InstrumentId\n\ndef validate_instrument_id_metadata(metadata: dict) -> str:\n    raw = metadata.get(\"instrument_id\")\n    if raw is not None:\n        InstrumentId.from_str(raw)  # raises a controlled error if invalid\n    return raw","typeGuard":"import re\n_INSTRUMENT_ID_RE = re.compile(r\"^[A-Za-z0-9._\\-]+\\.[A-Za-z0-9._\\-]+$\")\ndef is_instrument_id_str(s: str) -> bool:\n    return bool(_INSTRUMENT_ID_RE.match(s))","tryCatchPattern":"try:\n    instrument_id = data.instrument_id()\nexcept Exception as e:\n    logger.error(f\"malformed instrument_id in metadata: {metadata.get('instrument_id')!r}\")\n    raise","preventionTips":["Always write InstrumentId in SYMBOL.VENUE canonical format","Validate IDs via InstrumentId.from_str before storing in metadata","Check persisted/migrated data for legacy ID formats"],"tags":["rust","panic","instrument-id","metadata","parsing"],"backgroundTag":"invalid-argument-format","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"}