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 cold storage task has terminated.
34    ///
35    /// The channel is closed because the task has stopped (panic, cancellation,
36    /// or shutdown). This is persistent: all subsequent dispatches will fail
37    /// until the task is restarted.
38    ///
39    /// Hot storage remains consistent and authoritative. Cold storage can be
40    /// replayed from hot storage after task recovery.
41    #[error("cold storage task terminated: channel closed")]
42    TaskTerminated,
43}
44
45impl ColdStorageError {
46    /// Create a new backend error from any error type.
47    pub fn backend<E>(error: E) -> Self
48    where
49        E: core::error::Error + Send + Sync + 'static,
50    {
51        Self::Backend(Box::new(error))
52    }
53}