use std::fmt;
#[derive(Debug)]
pub enum EngineError {
User(String),
Internal(String),
Io(String),
Sql(String),
NotFound(String),
Other(String),
}
impl fmt::Display for EngineError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
EngineError::User(s) => write!(f, "user error: {s}"),
EngineError::Internal(s) => write!(f, "internal error: {s}"),
EngineError::Io(s) => write!(f, "io error: {s}"),
EngineError::Sql(s) => write!(f, "sql error: {s}"),
EngineError::NotFound(s) => write!(f, "not found: {s}"),
EngineError::Other(s) => write!(f, "{s}"),
}
}
}
impl std::error::Error for EngineError {}
impl From<serde_json::Error> for EngineError {
fn from(e: serde_json::Error) -> Self {
EngineError::Internal(e.to_string())
}
}
impl From<std::io::Error> for EngineError {
fn from(e: std::io::Error) -> Self {
EngineError::Io(e.to_string())
}
}