{"record":{"id":"8522e720eacc57f3","repo":"nautechsystems/nautilus_trader","slug":"cannot-setup-bar-aggregator-no-aggregator-found-f","errorCode":null,"errorMessage":"Cannot setup bar aggregator: no aggregator found for {bar_type}","messagePattern":"Cannot setup bar aggregator: no aggregator found for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/data/src/engine/mod.rs","lineNumber":5051,"sourceCode":"            );\n            return Some(SubscribeCommand::Quotes(subscribe));\n        }\n\n        None\n    }\n\n    /// Sets up a bar aggregator.\n    ///\n    /// This method handles historical mode, message bus subscriptions, and time bar aggregator setup.\n    fn setup_bar_aggregator(\n        &self,\n        bar_type: BarType,\n        historical: bool,\n        request_id: Option<UUID4>,\n    ) -> anyhow::Result<()> {\n        let key = bar_aggregator_key(bar_type, request_id);\n        let aggregator = self.bar_aggregators.get(&key).ok_or_else(|| {\n            anyhow::anyhow!(\"Cannot setup bar aggregator: no aggregator found for {bar_type}\")\n        })?;\n\n        // Set historical mode and handler\n        let cache = self.cache.clone();\n        let validate_sequence = self.config.validate_data_sequence;\n        let publish = !historical;\n        let handler: Box<dyn FnMut(Bar)> = Box::new(move |bar: Bar| {\n            process_engine_bar(&cache, validate_sequence, publish, bar);\n        });\n\n        aggregator\n            .borrow_mut()\n            .set_historical_mode(historical, handler);\n\n        // For TimeBarAggregator, set clock and start timer\n        if bar_type.spec().is_time_aggregated() {\n            use nautilus_common::clock::TestClock;\n","sourceCodeStart":5033,"sourceCodeEnd":5069,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/data/src/engine/mod.rs#L5033-L5069","documentation":"setup_bar_aggregator requires an already-created aggregator in the bar_aggregators map for the given BarType/key. This function only configures (historical mode, handler, sequence validation) an existing aggregator; it never creates one. If none exists, the caller invoked setup out of order.","triggerScenarios":"Calling setup_bar_aggregator (internal, from subscribe_bars handler wiring or replay paths) before start_bar_aggregation/create_bar_aggregator_for_key ran, or after stop_bar_aggregator removed the entry, or with a request_id that doesn't match the one used at creation.","commonSituations":"Replay/backtest code paths setting up aggregation twice; calling stop then setup on the same bar type; mismatched request_id between create and setup calls.","solutions":["Ensure start_bar_aggregation (or the create step) is called for the bar_type before setup_bar_aggregator.","Check that the same request_id is passed to both creation and setup — a None vs Some(UUID4) mismatch changes the key.","If the aggregator was stopped, recreate it via start_bar_aggregation rather than re-running setup.","Inspect bar_aggregators keys (via debug logging) to confirm the expected key exists."],"exampleFix":"// before\nengine.setup_bar_aggregator(bar_type, historical, request_id);\n// after\nengine.start_bar_aggregation(bar_type, None, false)?;\nengine.setup_bar_aggregator(bar_type, historical, request_id)?;","handlingStrategy":"validation","validationCode":"// ensure aggregation was started before setup\nengine.start_bar_aggregation(bar_type, None, false)?;\nengine.setup_bar_aggregator(bar_type, historical, request_id)?;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Follow create -> setup -> use ordering for aggregator lifecycle.","Never call setup after stop; recreate instead.","Use identical request_id values across lifecycle calls.","Track per-bar-type lifecycle state in application code."],"tags":["rust","data-engine","bar-aggregation","lifecycle-order"],"backgroundTag":"invalid-state-transition","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"}