use config::ConfigError;
use std::{fmt::Display, io};
use tokio::sync::mpsc::error::SendError;
#[derive(Debug)]
pub enum AppError<T> {
Io(io::Error),
Send(SendError<T>),
Config(ConfigError),
InvalidAction(String),
InvalidEvent(String),
AlreadyBound,
InvalidColor(String),
}
impl<T> From<io::Error> for AppError<T> {
fn from(error: io::Error) -> Self {
Self::Io(error)
}
}
impl<T> From<SendError<T>> for AppError<T> {
fn from(error: SendError<T>) -> Self {
Self::Send(error)
}
}
impl<T> From<ConfigError> for AppError<T> {
fn from(error: ConfigError) -> Self {
Self::Config(error)
}
}
impl<T> Display for AppError<T> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Io(error) => write!(f, "IO error: {}", error),
Self::Send(error) => write!(f, "Send error: {}", error),
Self::Config(error) => write!(f, "Config error: {}", error),
Self::InvalidAction(action) => {
write!(f, "Invalid action: {}", action)
}
Self::InvalidEvent(event) => {
write!(f, "Invalid event: {}", event)
}
Self::AlreadyBound => {
write!(f, "Key already bound")
}
Self::InvalidColor(color) => {
write!(f, "Invalid color: {}", color)
}
}
}
}