discord-kurante/src/util/error.rs

23 lines
554 B
Rust

pub enum KuranteError {
MissingEnvVar(std::env::VarError),
Bot(serenity::Error),
InvalidToken,
Database(sqlx::Error),
}
/// Generates a from implementation from the specified type to the provided
/// bunbun error.
macro_rules! from_error {
($from:ty, $to:ident) => {
impl From<$from> for KuranteError {
fn from(e: $from) -> Self {
Self::$to(e)
}
}
};
}
from_error!(std::env::VarError, MissingEnvVar);
from_error!(serenity::Error, Bot);
from_error!(sqlx::Error, Database);