82 lines
2.3 KiB
Rust
82 lines
2.3 KiB
Rust
use crate::user;
|
|
use magick_rust::MagickError;
|
|
use serde::ser::StdError;
|
|
use std::fmt::{write, Display, Formatter};
|
|
|
|
#[derive(Debug)]
|
|
#[allow(clippy::enum_variant_names)]
|
|
#[allow(dead_code)]
|
|
pub enum Error {
|
|
ConfigError(config::ConfigError),
|
|
SerenityError(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),
|
|
}
|
|
|
|
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(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 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),
|
|
}
|
|
}
|
|
}
|