remake error in libpt-log
cargo devel CI / cargo CI (push) Successful in 2m17s Details

This commit is contained in:
Christoph J. Scherr 2024-02-01 22:55:20 +01:00
parent a150304d01
commit 3d727c74d0
Signed by: PlexSheep
GPG Key ID: 7CDD0B14851A08EF
1 changed files with 7 additions and 27 deletions

View File

@ -26,45 +26,25 @@ use tracing::subscriber::SetGlobalDefaultError;
//// ENUMS ///////////////////////////////////////////////////////////////////////////////////////// //// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
/// ## Errors for the [Logger](super::Logger) /// ## Errors for the [Logger](super::Logger)
#[derive(Error)] #[derive(Error, Debug)]
pub enum Error { pub enum Error {
/// Bad IO operation /// Bad IO operation
#[error("Bad IO operation")] #[error("Bad IO operation")]
IO(std::io::Error), IO(#[from] std::io::Error),
/// Various errors raised when the messenger is used in a wrong way /// Various errors raised when the messenger is used in a wrong way
#[error("Bad usage")] #[error("Bad usage")]
Usage(String), Usage(String),
/// Could not assign logger as the global default /// Could not assign logger as the global default
#[error("Could not assign as global default")] // TODO: make this more clear #[error("Could not assign logger as global default")]
SetGlobalDefaultFail(SetGlobalDefaultError), SetGlobalDefaultFail(#[from] SetGlobalDefaultError),
/// any other error type, wrapped in [anyhow::Error](anyhow::Error)
#[error(transparent)]
Other(#[from] anyhow::Error),
} }
//// STRUCTS /////////////////////////////////////////////////////////////////////////////////////// //// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
//// IMPLEMENTATION //////////////////////////////////////////////////////////////////////////////// //// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Error::IO(value)
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
impl From<SetGlobalDefaultError> for Error {
fn from(value: SetGlobalDefaultError) -> Self {
Error::SetGlobalDefaultFail(value)
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
impl std::fmt::Debug for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::IO(e) => write!(f, "<IO Error {e:?}>"),
Error::Usage(e) => write!(f, "<Usage Error {e:?}>"),
Error::SetGlobalDefaultFail(e) => write!(f, "<SetGlobalDefaultFail {e:?}>"),
}
}
}
//// PUBLIC FUNCTIONS ////////////////////////////////////////////////////////////////////////////// //// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////