use globset::Error as GlobSetError;
#[derive(Debug)]
pub enum DatabaseError {
FileNotFound,
IOError(std::io::Error),
InvalidGlobSet(GlobSetError),
ChangeLogInUse,
PoisonedLogMutex,
}
impl std::fmt::Display for DatabaseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::FileNotFound => write!(f, "file not found in database"),
Self::IOError(err) => write!(f, "I/O error: {err}"),
Self::InvalidGlobSet(err) => write!(f, "failed to build exclusion filter from patterns: {err}"),
Self::ChangeLogInUse => {
write!(f, "cannot commit changelog because it is still in use by another thread")
}
Self::PoisonedLogMutex => {
write!(f, "changelog is in an unrecoverable state because a thread panicked while modifying it")
}
}
}
}
impl std::error::Error for DatabaseError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::IOError(err) => Some(err),
Self::InvalidGlobSet(err) => Some(err),
_ => None,
}
}
}
impl From<std::io::Error> for DatabaseError {
fn from(error: std::io::Error) -> Self {
Self::IOError(error)
}
}
impl From<GlobSetError> for DatabaseError {
fn from(error: GlobSetError) -> Self {
Self::InvalidGlobSet(error)
}
}