{"record":{"id":"680c3537c5b3a760","repo":"nautechsystems/nautilus_trader","slug":"dataactor-must-be-registered-before-accessing-cach","errorCode":null,"errorMessage":"DataActor must be registered before accessing cache","messagePattern":"DataActor must be registered before accessing cache","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/actor/data_actor.rs","lineNumber":219,"sourceCode":"    /// Panics if the actor has not yet been registered.\n    fn clock_rc(&self) -> Rc<RefCell<dyn Clock>> {\n        self.core()\n            .clock\n            .as_ref()\n            .expect(\"DataActor must be registered before accessing clock\")\n            .clone()\n    }\n\n    /// Returns a read-only cache borrow.\n    ///\n    /// # Panics\n    ///\n    /// Panics if the actor has not yet been registered.\n    fn cache_ref(&self) -> Ref<'_, Cache> {\n        self.core()\n            .cache\n            .as_ref()\n            .expect(\"DataActor must be registered before accessing cache\")\n            .borrow()\n    }\n\n    /// Returns a clone of the reference-counted cache.\n    ///\n    /// # Panics\n    ///\n    /// Panics if the actor has not yet been registered.\n    fn cache_rc(&self) -> Rc<RefCell<Cache>> {\n        self.core()\n            .cache\n            .as_ref()\n            .expect(\"DataActor must be registered before accessing cache\")\n            .clone()\n    }\n}\n\n/// Defines lifecycle callbacks, data handlers, and subscription/request","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/actor/data_actor.rs#L201-L237","documentation":"DataActor::cache_ref borrows the shared Cache for reading, but the cache handle is only populated when the actor is registered with a Trader/Node. Calling it before registration panics with this message, enforcing the actor lifecycle: no cache access before registration.","triggerScenarios":"Calling cache_ref() (directly or via helpers like cache_read) from the actor's constructor, before trader.add_actor/node registration, or in tests that build a bare DataActor without registering it.","commonSituations":"Attempting to read market data/prices in actor initialization code; unit tests instantiating the actor manually and calling data handlers without simulating registration; calling on_start-style logic too early.","solutions":["Access the cache only from lifecycle callbacks (on_start and later) that run after registration","Register the actor before invoking any cache-dependent method","In tests, register the actor with a test harness/kernel (or populate the core's cache) before exercising handlers"],"exampleFix":"// before\nlet prices = actor.cache_ref().prices(...); // panics if called pre-registration\n// after\n// inside on_start / on_data, post-registration:\nlet prices = self.cache_ref().prices(...);","handlingStrategy":"validation","validationCode":"// Ensure registration completed before any cache access:\n// e.g. call sites only in on_start/on_data, never in new().\nfn ensure_registered(registered: bool) {\n    assert!(registered, \"cache access requires registration\");\n}","typeGuard":null,"tryCatchPattern":"// Panics are not catchable; enforce ordering by only reading cache in lifecycle callbacks:\nfn on_start(&mut self) {\n    let cache = self.cache_ref(); // safe here\n}","preventionTips":["Read the cache only from on_start or later callbacks","Move any pre-registration cache reads into on_start","In unit tests, register the actor (or inject cache) before invoking data handlers"],"tags":["rust","panic","actor","cache","lifecycle"],"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-14T00:17:10.932Z"}