2023-09-20 20:14:10 +02:00
|
|
|
//! # Error module for [`pt-log`](crate)
|
2023-09-15 17:15:09 +02:00
|
|
|
//!
|
2023-09-20 20:14:10 +02:00
|
|
|
//! This module handles errors in logging contexts.
|
2023-09-15 17:15:09 +02:00
|
|
|
|
|
|
|
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// we want docs
|
|
|
|
#![warn(missing_docs)]
|
|
|
|
#![warn(rustdoc::missing_crate_level_docs)]
|
|
|
|
// we want Debug everywhere.
|
|
|
|
#![warn(missing_debug_implementations)]
|
|
|
|
// enable clippy's extra lints, the pedantic version
|
|
|
|
#![warn(clippy::pedantic)]
|
|
|
|
|
|
|
|
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
|
2024-01-16 10:18:29 +01:00
|
|
|
use anyhow;
|
|
|
|
use thiserror::Error;
|
2024-01-16 10:30:55 +01:00
|
|
|
use tracing::subscriber::SetGlobalDefaultError;
|
2023-09-15 17:15:09 +02:00
|
|
|
|
|
|
|
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//// MACROS ////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
|
2023-09-20 20:14:10 +02:00
|
|
|
/// ## Errors for the [Logger](super::Logger)
|
2024-01-16 10:18:29 +01:00
|
|
|
#[derive(Error)]
|
2023-09-15 17:15:09 +02:00
|
|
|
pub enum Error {
|
|
|
|
/// Bad IO operation
|
2024-01-16 10:18:29 +01:00
|
|
|
#[error("Bad IO operation")]
|
2023-09-15 17:15:09 +02:00
|
|
|
IO(std::io::Error),
|
|
|
|
/// Various errors raised when the messenger is used in a wrong way
|
2024-01-16 10:18:29 +01:00
|
|
|
#[error("Bad usage")]
|
2023-09-15 17:15:09 +02:00
|
|
|
Usage(String),
|
|
|
|
/// Could not assign logger as the global default
|
2024-01-16 10:18:29 +01:00
|
|
|
#[error("Could not assign as global default")] // TODO: make this more clear
|
2023-09-15 17:15:09 +02:00
|
|
|
SetGlobalDefaultFail(SetGlobalDefaultError),
|
|
|
|
}
|
|
|
|
|
|
|
|
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//// 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 //////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
|