{"record":{"id":"467d4820bd227732","repo":"nautechsystems/nautilus_trader","slug":"instrumentid-not-applicable-to-block","errorCode":null,"errorMessage":"`InstrumentId` not applicable to `Block`","messagePattern":"`InstrumentId` not applicable to `Block`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/defi/data/mod.rs","lineNumber":226,"sourceCode":"            Self::PoolSnapshot(snapshot) => snapshot.ts_init,\n            Self::PoolSwap(swap) => swap.ts_init,\n            Self::PoolLiquidityUpdate(update) => update.ts_init,\n            Self::PoolFeeCollect(collect) => collect.ts_init,\n            Self::PoolFeeProtocolUpdate(update) => update.ts_init,\n            Self::PoolFeeProtocolCollect(collect) => collect.ts_init,\n            Self::PoolFlash(flash) => flash.ts_init,\n        }\n    }\n\n    /// Returns the instrument ID associated with this DeFi data.\n    ///\n    /// # Panics\n    ///\n    /// Panics if the variant is a `Block` or `PoolSnapshot` where instrument IDs are not applicable.\n    #[must_use]\n    pub fn instrument_id(&self) -> InstrumentId {\n        match self {\n            Self::Block(_) => panic!(\"`InstrumentId` not applicable to `Block`\"), // TBD?\n            Self::PoolSnapshot(snapshot) => snapshot.instrument_id,\n            Self::PoolSwap(swap) => swap.instrument_id,\n            Self::PoolLiquidityUpdate(update) => update.instrument_id,\n            Self::PoolFeeCollect(collect) => collect.instrument_id,\n            Self::PoolFeeProtocolUpdate(update) => update.instrument_id,\n            Self::PoolFeeProtocolCollect(collect) => collect.instrument_id,\n            Self::Pool(pool) => pool.instrument_id,\n            Self::PoolFlash(flash) => flash.instrument_id,\n        }\n    }\n}\n\nimpl HasTsInit for DefiData {\n    fn ts_init(&self) -> UnixNanos {\n        self.ts_init()\n    }\n}\n","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/defi/data/mod.rs#L208-L244","documentation":"Data::instrument_id() panics for variants that conceptually have no instrument ID — Block and PoolSnapshot. The method is only meaningful for pool events (swaps, liquidity updates, fee events). The panic guards against silently returning a meaningless default identifier.","triggerScenarios":"Calling data.instrument_id() on a Data::Block(_) or Data::PoolSnapshot(_) value, typically in generic code that processes every message from a DEX subscription identically.","commonSituations":"Generic data handlers/routers that dispatch on instrument_id without filtering by data type; test harnesses iterating all Data variants; subscribing to block streams and reusing pool-event handling code.","solutions":["Match on the Data variant first and only call instrument_id() for PoolSwap/PoolLiquidityUpdate/PoolFee* variants","Skip Block and PoolSnapshot messages in code paths that need an instrument ID","Use a helper that returns Option<InstrumentId> in your own code"],"exampleFix":"// before\nlet id = data.instrument_id(); // panics for Block\n// after\nlet id = match data {\n    Data::Block(_) | Data::PoolSnapshot(_) => None,\n    _ => Some(data.instrument_id()),\n};","handlingStrategy":"type-guard","validationCode":"fn instrument_id_of(data: &Data) -> Option<InstrumentId> {\n    match data {\n        Data::Block(_) | Data::PoolSnapshot(_) => None,\n        _ => Some(data.instrument_id()),\n    }\n}","typeGuard":"fn has_instrument_id(data: &Data) -> bool {\n    !matches!(data, Data::Block(_) | Data::PoolSnapshot(_))\n}","tryCatchPattern":"let id = std::panic::catch_unwind(|| data.instrument_id()).ok();","preventionTips":["Match on the Data variant before accessing instrument_id","Keep block/pool-snapshot handlers separate from pool-event handlers","Use your own Option-returning wrapper in shared routing code"],"tags":["rust","panic","defi","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}