use crate::logger::*;
#[derive(Debug)]
pub enum LogfatherError {
LoggerAccessError(String),
FileAccessError(String),
IoError(std::io::Error),
}
impl std::fmt::Display for LogfatherError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
LogfatherError::LoggerAccessError(err) => write!(f, "Failed to access logger: {err}"),
LogfatherError::FileAccessError(err) => write!(f, "Failed to access file: {err}"),
LogfatherError::IoError(err) => write!(f, "I/O Error: {err}"),
}
}
}
impl std::error::Error for LogfatherError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
return match self {
LogfatherError::IoError(err) => err.source(),
_ => None,
};
}
}
impl From<std::sync::PoisonError<std::sync::RwLockReadGuard<'_, Logger>>> for LogfatherError {
fn from(value: std::sync::PoisonError<std::sync::RwLockReadGuard<'_, Logger>>) -> Self {
return Self::LoggerAccessError(value.to_string());
}
}
impl From<std::sync::PoisonError<std::sync::MutexGuard<'_, std::fs::File>>> for LogfatherError {
fn from(value: std::sync::PoisonError<std::sync::MutexGuard<'_, std::fs::File>>) -> Self {
return Self::FileAccessError(value.to_string());
}
}
impl From<std::io::Error> for LogfatherError {
fn from(value: std::io::Error) -> Self {
return Self::IoError(value);
}
}
pub type LogfatherResult = Result<(), LogfatherError>;