multi_tier_cache/
error.rs1use thiserror::Error;
2
3#[cfg(feature = "redis")]
4use redis::RedisError;
5
6pub type CacheResult<T> = std::result::Result<T, CacheError>;
8
9#[derive(Error, Debug, Clone)]
11pub enum CacheError {
12 #[error("Backend error: {0}")]
14 BackendError(String),
15 #[error("Serialization error: {0}")]
17 SerializationError(String),
18 #[error("Invalidation error: {0}")]
20 InvalidationError(String),
21 #[error("Configuration error: {0}")]
23 ConfigError(String),
24 #[error("Key not found")]
26 NotFound,
27 #[error("Internal error: {0}")]
29 InternalError(String),
30}
31
32#[cfg(feature = "redis")]
33impl From<RedisError> for CacheError {
34 fn from(err: RedisError) -> Self {
35 Self::BackendError(err.to_string())
36 }
37}
38
39impl From<serde_json::Error> for CacheError {
40 fn from(err: serde_json::Error) -> Self {
41 Self::SerializationError(err.to_string())
42 }
43}
44
45#[cfg(feature = "msgpack")]
46impl From<rmp_serde::decode::Error> for CacheError {
47 fn from(err: rmp_serde::decode::Error) -> Self {
48 Self::SerializationError(err.to_string())
49 }
50}
51
52impl From<std::num::TryFromIntError> for CacheError {
53 fn from(err: std::num::TryFromIntError) -> Self {
54 Self::ConfigError(err.to_string())
55 }
56}
57
58#[cfg(feature = "backend-memcached")]
59impl From<memcache::MemcacheError> for CacheError {
60 fn from(err: memcache::MemcacheError) -> Self {
61 Self::BackendError(err.to_string())
62 }
63}