#[cfg(not(feature = "web"))]
use crate::tui::event::Event;
use config::ConfigError;
#[cfg(not(feature = "web"))]
use tokio::sync::mpsc::error::SendError;
use tracing_subscriber::filter::ParseError;
#[derive(Debug)]
pub enum TuiError {
Reqwest(reqwest::Error),
Json(serde_json::Error),
IO(std::io::Error),
#[cfg(not(feature = "web"))]
SendError(Box<SendError<Event>>),
Config(Box<ConfigError>),
Tracing(Box<ParseError>),
}
impl std::fmt::Display for TuiError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TuiError::Reqwest(err) => write!(f, "Reqwest error: {err}"),
TuiError::Json(err) => write!(f, "JSON error: {err}"),
TuiError::IO(err) => write!(f, "An IO error occurred: {err}"),
#[cfg(not(feature = "web"))]
TuiError::SendError(err) => write!(f, "Send error: {err}"),
TuiError::Config(err) => write!(f, "Config error: {err}"),
TuiError::Tracing(err) => write!(f, "Tracing error: {err}"),
}
}
}
impl std::error::Error for TuiError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
TuiError::Reqwest(err) => Some(err),
TuiError::Json(err) => Some(err),
TuiError::IO(err) => Some(err),
#[cfg(not(feature = "web"))]
TuiError::SendError(err) => Some(err.as_ref()),
TuiError::Config(err) => Some(err.as_ref()),
TuiError::Tracing(err) => Some(err.as_ref()),
}
}
}
impl From<reqwest::Error> for TuiError {
fn from(err: reqwest::Error) -> Self {
TuiError::Reqwest(err)
}
}
impl From<serde_json::Error> for TuiError {
fn from(err: serde_json::Error) -> Self {
TuiError::Json(err)
}
}
#[cfg(not(feature = "web"))]
impl From<SendError<Event>> for TuiError {
fn from(err: SendError<Event>) -> Self {
TuiError::SendError(Box::new(err))
}
}
impl From<std::io::Error> for TuiError {
fn from(err: std::io::Error) -> Self {
TuiError::IO(err)
}
}
impl From<ConfigError> for TuiError {
fn from(err: ConfigError) -> Self {
TuiError::Config(Box::new(err))
}
}
impl From<ParseError> for TuiError {
fn from(err: ParseError) -> Self {
TuiError::Tracing(Box::new(err))
}
}