use std::path::PathBuf;
pub struct Error {
inner: ErrorInner,
}
#[derive(Debug)]
pub enum ErrorInner {
MakeTempDir(std::io::Error),
MakeDbDir(PathBuf, std::io::Error),
SpawnServer(String, std::io::Error),
KillServer(std::io::Error),
CleanDir(PathBuf, std::io::Error),
Connect(String, mongodb::error::Error),
}
impl std::error::Error for Error {}
impl std::fmt::Debug for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Debug::fmt(&self.inner, f)
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.inner, f)
}
}
impl std::fmt::Display for ErrorInner {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::MakeTempDir(e) => write!(f, "Failed to create temporary directory: {e}"),
Self::MakeDbDir(path, e) => write!(f, "Failed to create data directory {}: {e}", path.display()),
Self::SpawnServer(name, e) => write!(f, "Failed to run server command: {name}: {e}"),
Self::KillServer(e) => write!(f, "Failed to terminate spanwed server: {e}"),
Self::CleanDir(path, e) => write!(f, "Failed to clean up temporary state directory {}: {e}", path.display()),
Self::Connect(address, e) => write!(f, "Failed to connect to server at {address}: {e}"),
}
}
}
impl From<ErrorInner> for Error {
fn from(inner: ErrorInner) -> Self {
Self { inner }
}
}