{"record":{"id":"1932ce447546e405","repo":"nautechsystems/nautilus_trader","slug":"cannot-extract-snapshot-no-events-processed-yet","errorCode":null,"errorMessage":"Cannot extract snapshot: no events processed yet","messagePattern":"Cannot extract snapshot: no events processed yet","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/defi/pool_analysis/profiler.rs","lineNumber":1882,"sourceCode":"    /// all liquidity positions, and the full tick distribution into a portable\n    /// [`PoolSnapshot`] structure. This snapshot can be serialized, persisted\n    /// to database, or used to restore pool state later.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if no events have been processed yet, since there is no event watermark to\n    /// anchor the snapshot to.\n    pub fn extract_snapshot(&self) -> anyhow::Result<PoolSnapshot> {\n        let positions: Vec<_> = self.positions.values().cloned().collect();\n        let ticks: Vec<_> = self.tick_map.get_all_ticks().values().copied().collect();\n\n        let mut state = self.state.clone();\n        state.liquidity = self.tick_map.liquidity;\n\n        let last_processed_event = self\n            .last_processed_event\n            .clone()\n            .ok_or_else(|| anyhow::anyhow!(\"Cannot extract snapshot: no events processed yet\"))?;\n\n        Ok(PoolSnapshot::new(\n            self.pool.instrument_id,\n            state,\n            positions,\n            ticks,\n            self.analytics.clone(),\n            last_processed_event,\n            self.last_processed_ts.unwrap_or(self.pool.ts_init), // ts_event (last processed event)\n            self.last_processed_ts.unwrap_or(self.pool.ts_init), // ts_init\n        ))\n    }\n\n    /// Gets the count of positions that are currently active.\n    ///\n    /// Active positions are those with liquidity > 0 and whose tick range\n    /// includes the current pool tick (meaning they have tokens in the pool).\n    #[must_use]","sourceCodeStart":1864,"sourceCodeEnd":1900,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/defi/pool_analysis/profiler.rs#L1864-L1900","documentation":"`extract_snapshot` serializes the profiler's full state (positions, ticks, fee model) into a `PoolSnapshot` for checkpoint/restore. A snapshot includes `last_processed_event` so a restored profiler can resume replay correctly; if no event has ever been processed, there is no resume point, so the method errors instead of producing a snapshot with undefined provenance.","triggerScenarios":"Calling `extract_snapshot` on a freshly constructed `PoolProfiler` before any event has been applied via `process`/`process_defi_data` — i.e. `last_processed_event` is `None`.","commonSituations":"Checkpointing logic that runs too early in a replay pipeline; test code snapshotting a newly built profiler; resuming a job whose profiler was rebuilt but not yet fed any events.","solutions":["Process at least one pool event before calling `extract_snapshot`.","Guard the call: check whether any events were processed and skip/make a fresh snapshot from genesis instead.","If you need a baseline snapshot of an untouched pool, represent it as 'no snapshot / start from genesis' in your checkpoint scheme.","In tests, drive the profiler with one synthetic event before extracting a snapshot."],"exampleFix":"// before\nlet snapshot = profiler.extract_snapshot()?; // Err if nothing processed\n// after\nlet snapshot = match profiler.extract_snapshot() {\n    Ok(s) => Some(s),\n    Err(e) if e.to_string().contains(\"no events processed yet\") => None, // start from genesis\n    Err(e) => return Err(e),\n};","handlingStrategy":"validation","validationCode":"fn can_snapshot(profiler: &PoolProfiler) -> bool { profiler.last_processed_event.is_some() }","typeGuard":null,"tryCatchPattern":"let snapshot = profiler.extract_snapshot()\n    .map(Some)\n    .or_else(|e| if e.to_string().contains(\"no events processed yet\") { Ok(None) } else { Err(e) })?;","preventionTips":["Only checkpoint after the replay loop has applied events","Treat an unprocessed profiler as genesis rather than erroring in your checkpoint layer","Add an assertion/log when snapshotting early in pipelines"],"tags":["defi","state-management","precondition"],"backgroundTag":"empty-required-field","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"}