use thiserror::Error;
#[derive(Debug, Error)]
pub enum SentinelPoolError {
#[error("redis error: {0}")]
Redis(#[from] redis::RedisError),
#[error("connection pool error: {0}")]
Pool(String),
#[error("invalid configuration: {0}")]
Config(String),
#[error("operation failed after {attempts} attempts: {source}")]
RetryExhausted {
attempts: u32,
#[source]
source: redis::RedisError,
},
#[error("sentinel watcher stopped: {0}")]
WatcherStopped(String),
}
pub type Result<T> = std::result::Result<T, SentinelPoolError>;
impl<E> From<bb8::RunError<E>> for SentinelPoolError
where
E: Into<SentinelPoolError> + std::fmt::Display,
{
fn from(value: bb8::RunError<E>) -> Self {
match value {
bb8::RunError::User(e) => e.into(),
bb8::RunError::TimedOut => SentinelPoolError::Pool("timed out waiting for connection".into()),
}
}
}