use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Clone, thiserror::Error)]
pub enum ConfigurationError {
#[error("cache_size must be greater than 0, got {0}")]
InvalidCacheSize(usize),
#[error("max_connections must be greater than 0, got {0}")]
InvalidMaxConnections(u32),
#[error("table_name is invalid: {0}")]
InvalidTableName(String),
#[error("backoff configuration is invalid: {0}")]
InvalidBackoff(String),
}
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Database error: {0}")]
Database(String),
#[error("Connection pool error: {0}")]
ConnectionPool(String),
#[error("Cache error: {0}")]
Cache(String),
#[error("Configuration error: {0}")]
Configuration(#[from] ConfigurationError),
#[error("Invalid URI: {0}")]
InvalidUri(String),
}
impl Error {
pub fn connection_pool(msg: impl fmt::Display) -> Self {
Self::ConnectionPool(msg.to_string())
}
pub fn cache(msg: impl fmt::Display) -> Self {
Self::Cache(msg.to_string())
}
pub fn invalid_uri(msg: impl fmt::Display) -> Self {
Self::InvalidUri(msg.to_string())
}
}