sisa_caching_hybrid/error.rs
1//! The hybrid store's errors.
2
3use sisa_caching_core::cache::CacheError;
4
5type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
6
7/// Errors from the hybrid store, by the layer they came from.
8#[derive(Debug, thiserror::Error)]
9#[non_exhaustive]
10pub enum HybridCacheError {
11 /// A bad store name or setting, or a `CacheOptions` TTL over 365 days, rejected before anything
12 /// is evicted or written. Local type mismatches read through, and the distributed store's
13 /// errors are `Distributed`.
14 #[error(transparent)]
15 Cache(#[from] CacheError),
16
17 /// An error from the distributed store, boxed. For a
18 /// [`RedisHybridCacheStore`](crate::RedisHybridCacheStore), downcast it to reach the Redis
19 /// error:
20 ///
21 /// ```
22 /// use sisa_caching_hybrid::HybridCacheError;
23 /// use sisa_caching_redis::RedisCacheError;
24 ///
25 /// fn redis_error(error: &HybridCacheError) -> Option<&RedisCacheError> {
26 /// match error {
27 /// HybridCacheError::Distributed(source) => source.downcast_ref(),
28 /// _ => None,
29 /// }
30 /// }
31 /// ```
32 #[error("distributed layer: {0}")]
33 Distributed(#[source] BoxError),
34
35 /// The write task panicked, or the runtime shut down before it finished.
36 #[error("write stopped before reporting its result")]
37 WriteStopped(#[from] tokio::task::JoinError),
38}
39
40impl HybridCacheError {
41 pub(crate) fn distributed(error: impl std::error::Error + Send + Sync + 'static) -> Self {
42 Self::Distributed(Box::new(error))
43 }
44}
45
46/// A `Result` whose error is a [`HybridCacheError`].
47pub type Result<T> = std::result::Result<T, HybridCacheError>;