1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum Error {
8 #[error("Key not found: {0}")]
10 NotFound(String),
11
12 #[error("Serialization error: {0}")]
14 Serialization(String),
15
16 #[error("Deserialization error: {0}")]
18 Deserialization(String),
19
20 #[error("Connection error: {0}")]
22 Connection(String),
23
24 #[error("Store not configured: {0}")]
26 StoreNotConfigured(String),
27
28 #[cfg(feature = "redis-backend")]
30 #[error("Redis error: {0}")]
31 Redis(#[from] redis::RedisError),
32}
33
34impl Error {
35 pub fn not_found(key: impl Into<String>) -> Self {
37 Self::NotFound(key.into())
38 }
39
40 pub fn serialization(msg: impl Into<String>) -> Self {
42 Self::Serialization(msg.into())
43 }
44
45 pub fn deserialization(msg: impl Into<String>) -> Self {
47 Self::Deserialization(msg.into())
48 }
49
50 pub fn connection(msg: impl Into<String>) -> Self {
52 Self::Connection(msg.into())
53 }
54
55 pub fn store_not_configured(store: impl Into<String>) -> Self {
57 Self::StoreNotConfigured(store.into())
58 }
59}