FrenBot/src/error.rs
2025-08-04 17:56:46 -06:00

127 lines
3.7 KiB
Rust

use crate::discord::voices::VoiceError;
use crate::image_manipulation::ModifyImageArgError;
use crate::user;
use magick_rust::MagickError;
use serde::ser::StdError;
use std::fmt::{Display, Formatter};
#[derive(Debug)]
#[allow(clippy::enum_variant_names)]
#[allow(dead_code)]
pub enum Error {
ConfigError(config::ConfigError),
SerenityError(Box<poise::serenity_prelude::Error>),
TeraError(tera::Error),
NoAlbumFound,
UserError(user::UserError),
DbError(j_db::error::JDbError),
ReqwestError(reqwest::Error),
ParseFailure,
RaasError(String),
MagickError(magick_rust::MagickError),
CommandError(String),
IoError(std::io::Error),
VoiceError(Box<VoiceError>),
CTAError(cta_api::Error),
NoImageFound,
PipelineArgumentError(ModifyImageArgError),
NoRandomFound,
NotEnoughGogurt,
}
impl StdError for Error {}
impl From<config::ConfigError> for Error {
fn from(e: config::ConfigError) -> Self {
Self::ConfigError(e)
}
}
impl From<poise::serenity_prelude::Error> for Error {
fn from(err: poise::serenity_prelude::Error) -> Self {
Self::SerenityError(Box::new(err))
}
}
impl From<tera::Error> for Error {
fn from(err: tera::Error) -> Self {
Self::TeraError(err)
}
}
impl From<user::UserError> for Error {
fn from(err: user::UserError) -> Self {
Self::UserError(err)
}
}
impl From<j_db::error::JDbError> for Error {
fn from(err: j_db::error::JDbError) -> Self {
Self::DbError(err)
}
}
impl From<reqwest::Error> for Error {
fn from(err: reqwest::Error) -> Self {
Self::ReqwestError(err)
}
}
impl From<magick_rust::MagickError> for Error {
fn from(value: MagickError) -> Self {
Self::MagickError(value)
}
}
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Self::IoError(value)
}
}
impl From<VoiceError> for Error {
fn from(value: VoiceError) -> Self {
Self::VoiceError(Box::new(value))
}
}
impl From<cta_api::Error> for Error {
fn from(value: cta_api::Error) -> Self {
Self::CTAError(value)
}
}
impl From<ModifyImageArgError> for Error {
fn from(value: ModifyImageArgError) -> Self {
Self::PipelineArgumentError(value)
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Error::ConfigError(e) => write!(f, "Config error: {e}"),
Error::SerenityError(e) => write!(f, "Discord error: {e}"),
Error::TeraError(e) => write!(f, "Tera error: {e}"),
Error::NoAlbumFound => write!(f, "No album found"),
Error::UserError(e) => write!(f, "User error: {e}"),
Error::DbError(e) => write!(f, "DB error: {e}"),
Error::ReqwestError(e) => write!(f, "Reqwest Error: {e}"),
Error::ParseFailure => write!(f, "Failed to parse something or other"),
Error::RaasError(msg) => write!(f, "Got error from RaaS: {msg}"),
Error::MagickError(err) => write!(f, "ImageMagick error: {err}"),
Error::CommandError(err_msg) => write!(f, "{err_msg}"),
Error::IoError(err) => write!(f, "IO Error: {err}"),
Error::VoiceError(err) => write!(f, "Voice error: {err}"),
Error::CTAError(err) => write!(f, "The CTA had an error, I'm shocked: {err}"),
Error::NoImageFound => write!(f, "Image not found"),
Error::PipelineArgumentError(err) => write!(f, "{err}"),
Error::NoRandomFound => write!(f, "No random found"),
Error::NotEnoughGogurt => write!(
f,
"Wow, you really don't have enough gogurt. What are you 12?? Just got buy some poor."
),
}
}
}