Skip to main content

pyra_redis/
error.rs

1/// Redis operation errors.
2#[derive(Debug, thiserror::Error)]
3pub enum RedisError {
4    /// Failed to obtain a connection from the pool.
5    #[error("Redis pool error: {0}")]
6    Pool(#[from] deadpool_redis::PoolError),
7    /// Redis command failed.
8    #[error("Redis error: {0}")]
9    Redis(#[from] redis::RedisError),
10    /// JSON serialization/deserialization failed.
11    #[error("Serialization error: {0}")]
12    Serialization(#[from] serde_json::Error),
13    /// Invalid pool configuration.
14    #[error("Pool config error: {0}")]
15    PoolConfig(#[from] deadpool_redis::ConfigError),
16    /// Failed to build connection pool.
17    #[error("Pool build error: {0}")]
18    PoolBuild(#[from] deadpool_redis::BuildError),
19    /// Expected data was not found in Redis.
20    #[error("Not found: {0}")]
21    NotFound(String),
22    /// Arithmetic overflow during position computation.
23    #[error("Math overflow")]
24    MathOverflow,
25}
26
27impl From<pyra_margin::MathError> for RedisError {
28    fn from(_: pyra_margin::MathError) -> Self {
29        Self::MathOverflow
30    }
31}
32
33pub type RedisResult<T> = Result<T, RedisError>;