use std::error::Error;
use std::sync::Arc;
use crate::commands::permissions::PermissionError;
#[derive(Debug, thiserror::Error, Clone)]
pub enum CommandError {
#[error("An error occurred while getting the prefixes for a message: {0}")]
Prefixes(Arc<dyn Error + Send + Sync>),
#[error("An error occurred while parsing a command's arguments: {0}")]
Arguments(#[from] ArgumentError),
#[error("An error occurred while checking for a command's permissions: {0}")]
Permissions(PermissionError),
#[error("An error occurred while running a command: {0}")]
Runtime(Arc<dyn Error + Send + Sync>),
}
#[derive(Debug, thiserror::Error, Clone)]
pub enum ArgumentError {
#[error("A required argument was missing.")]
Missing,
#[error("An argument required (its own) metadata, but it was missing.")]
MissingMeta,
#[error("A command was run with an argument that requires more information from Discord, but Discord didn't send such information.")]
MissingResolved,
#[error("An argument was improperly formatted.")]
Misformatted,
#[error("An argument was received with an incorrect type.")]
Mistyped,
#[error("An argument was received within the wrong context.")]
WrongContext,
#[error("An unknown error occurred while parsing an argument: {0}")]
Runtime(Arc<dyn Error + Send + Sync>),
}
impl ArgumentError {
pub fn new(error: impl Error + Send + Sync + 'static) -> Self {
Self::Runtime(Arc::new(error))
}
}