use std::fmt;
#[derive(Debug, Clone)]
pub enum Error {
Internal(String),
IO(std::io::ErrorKind),
Bson(mongodb::bson::de::Error),
Mongo(mongodb::error::Error),
TestError(String),
SharedSessionLockFailure(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Internal(err) => write!(f, "Internal Error: {err}"),
Self::IO(err) => write!(f, "IO Error: {:?}", err),
Self::Bson(err) => write!(f, "Bson Error: {:?}", err),
Self::Mongo(err) => write!(f, "Mongo Error: {:?}", err),
Self::TestError(err) => write!(f, "Test Error: {err}"),
Self::SharedSessionLockFailure(err) => {
write!(f, "SharedSessionLockFailure Error: {err}")
}
}
}
}
impl std::error::Error for Error {}
impl Error {
pub fn internal(message: &str) -> Self {
Self::Internal(message.to_string())
}
}