Skip to main content

signet_cold/
error.rs

1//! Error types for cold storage operations.
2
3/// Result type alias for cold storage operations.
4pub type ColdResult<T, E = ColdStorageError> = Result<T, E>;
5
6/// Error type for cold storage operations.
7#[derive(Debug, thiserror::Error)]
8pub enum ColdStorageError {
9    /// An error occurred in the storage backend.
10    #[error("Backend error: {0}")]
11    Backend(#[from] Box<dyn core::error::Error + Send + Sync + 'static>),
12
13    /// The requested resource was not found.
14    #[error("Not found: {0}")]
15    NotFound(String),
16
17    /// The storage task was cancelled.
18    #[error("Task cancelled")]
19    Cancelled,
20
21    /// The cold storage task cannot keep up with incoming requests.
22    ///
23    /// The channel is full, indicating transient backpressure. The cold storage
24    /// task is still running but processing requests slower than they arrive.
25    ///
26    /// Callers may:
27    /// - Accept the gap (hot storage is authoritative) and repair later
28    /// - Retry after a delay with exponential backoff
29    /// - Increase channel capacity at construction time
30    #[error("cold storage backpressure: channel full")]
31    Backpressure,
32
33    /// The query matched more logs than the caller-specified `max_logs` limit.
34    ///
35    /// The query is rejected entirely rather than returning a partial result.
36    /// Callers should narrow the filter (smaller block range, more specific
37    /// address/topic filters) or increase the limit.
38    #[error("too many logs: query exceeds {limit}")]
39    TooManyLogs {
40        /// The limit that was exceeded.
41        limit: usize,
42    },
43
44    /// The cold storage task has terminated.
45    ///
46    /// The channel is closed because the task has stopped (panic, cancellation,
47    /// or shutdown). This is persistent: all subsequent dispatches will fail
48    /// until the task is restarted.
49    ///
50    /// Hot storage remains consistent and authoritative. Cold storage can be
51    /// replayed from hot storage after task recovery.
52    #[error("cold storage task terminated: channel closed")]
53    TaskTerminated,
54}
55
56impl ColdStorageError {
57    /// Create a new backend error from any error type.
58    pub fn backend<E>(error: E) -> Self
59    where
60        E: core::error::Error + Send + Sync + 'static,
61    {
62        Self::Backend(Box::new(error))
63    }
64}