use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Debug, thiserror::Error, PartialEq, Serialize, Deserialize)]
pub enum Error {
#[error("Codec error: {0}")]
Codec(String),
#[error("Cache miss for key")]
CacheMiss,
#[error("Backend error: {0}")]
Backend(String),
#[error("global cache has already been initialized")]
AlreadyInitialized,
#[error("Feature not implemented: {0}")]
NotImplemented(String),
#[error("Failed to acquire lock")]
LockError,
#[error("Key not found in registered warmers")]
KeyNotFound,
#[error("Cache error: {0}")]
Other(String),
}
impl Error {
pub fn backend<E: fmt::Display>(error: E) -> Self {
Self::Backend(error.to_string())
}
pub fn other<E: fmt::Display>(error: E) -> Self {
Self::Other(error.to_string())
}
}
pub type Result<T> = std::result::Result<T, Error>;
impl From<std::io::Error> for Error {
fn from(error: std::io::Error) -> Self {
Error::Backend(format!("I/O error: {}", error))
}
}