{"record":{"id":"e5ed937c88906d8c","repo":"nautechsystems/nautilus_trader","slug":"instrument-id-not-set","errorCode":null,"errorMessage":"Instrument ID not set","messagePattern":"Instrument ID not set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/orders/builder.rs","lineNumber":155,"sourceCode":"\n    // ----------- StrategyId ----------\n    pub fn strategy_id(&mut self, strategy_id: StrategyId) -> &mut Self {\n        self.strategy_id = Some(strategy_id);\n        self\n    }\n\n    fn get_strategy_id(&self) -> StrategyId {\n        self.strategy_id.unwrap_or_else(StrategyId::test_default)\n    }\n\n    // ----------- InstrumentId ----------\n    pub fn instrument_id(&mut self, instrument_id: InstrumentId) -> &mut Self {\n        self.instrument_id = Some(instrument_id);\n        self\n    }\n\n    fn get_instrument_id(&self) -> InstrumentId {\n        self.instrument_id.expect(\"Instrument ID not set\")\n    }\n\n    // ----------- ClientOrderId ----------\n    pub fn client_order_id(&mut self, client_order_id: ClientOrderId) -> &mut Self {\n        self.client_order_id = Some(client_order_id);\n        self\n    }\n\n    fn get_client_order_id(&self) -> ClientOrderId {\n        self.client_order_id\n            .unwrap_or_else(ClientOrderId::test_default)\n    }\n\n    // ----------- OrderSide ----------\n    pub fn side(&mut self, side: OrderSide) -> &mut Self {\n        self.side = Some(side);\n        self\n    }","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/orders/builder.rs#L137-L173","documentation":"OrderTestBuilder::get_instrument_id unwraps the Option<InstrumentId> set via .instrument_id(...). Calling build() without first setting an instrument id panics with 'Instrument ID not set'. The builder treats required fields as panics rather than Result-returning errors.","triggerScenarios":"Calling OrderTestBuilder::build() without chaining .instrument_id(InstrumentId) beforehand; the panic is raised inside get_instrument_id during build.","commonSituations":"Test code copying an existing builder invocation and forgetting the instrument_id line, or refactoring helpers where the instrument id became conditional.","solutions":["Add .instrument_id(...) to the builder chain before calling build().","Centralize a helper that supplies a default test instrument id.","Check that the value passed is a valid InstrumentId::from(\"BTCUSDT.BINANCE\")-style identifier, not just present."],"exampleFix":"// before\nlet order = OrderTestBuilder::new(OrderType::Limit).quantity(qty).build();\n// after\nlet order = OrderTestBuilder::new(OrderType::Limit)\n    .instrument_id(InstrumentId::from(\"BTCUSDT.BINANCE\"))\n    .quantity(qty)\n    .build();","handlingStrategy":"validation","validationCode":"let mut b = OrderTestBuilder::new(OrderType::Limit);\nassert!(instrument_id.is_some(), \"instrument_id must be set before build()\");\nb.instrument_id(instrument_id.unwrap()).build();","typeGuard":"fn requires_instrument_id(b: &OrderTestBuilder) -> bool { true } // every build() needs it; assert presence in your fixture instead","tryCatchPattern":"// builder panics are not catchable panics you should rely on; validate inputs before build\nassert!(instrument_id.is_some());","preventionTips":["Always include .instrument_id(...) as the first link in the builder chain.","Wrap OrderTestBuilder in a project-local fixture with required defaults.","Review builder chains after refactors to ensure required fields were not dropped."],"tags":["rust","panic","builder","missing-field","testing"],"backgroundTag":"missing-required-argument","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"}