use std::error::Error as StdError;
use std::fmt;
use super::Permissions;
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub enum Error {
BulkDeleteAmount,
DeleteMessageDaysAmount(u8),
EmbedAmount,
EmbedTooLarge(usize),
GuildNotFound,
RoleNotFound,
MemberNotFound,
ChannelNotFound,
MessageAlreadyCrossposted,
CannotCrosspostMessage,
Hierarchy,
InvalidPermissions {
required: Permissions,
present: Permissions,
},
InvalidUser,
ItemMissing,
WrongGuild,
MessageTooLong(usize),
MessagingBot,
InvalidChannelType,
NameTooShort,
NameTooLong,
NotAuthor,
NoTokenSet,
DeleteNitroSticker,
NoStickerFileSet,
StickerAmount,
CannotEditVoiceMessage,
}
impl Error {
#[must_use]
pub const fn is_cache_err(&self) -> bool {
matches!(
self,
Self::ItemMissing
| Self::ChannelNotFound
| Self::RoleNotFound
| Self::GuildNotFound
| Self::MemberNotFound
)
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::BulkDeleteAmount => f.write_str("Too few/many messages to bulk delete."),
Self::DeleteMessageDaysAmount(_) => f.write_str("Invalid delete message days."),
Self::EmbedAmount => f.write_str("Too many embeds in a message."),
Self::EmbedTooLarge(_) => f.write_str("Embed too large."),
Self::GuildNotFound => f.write_str("Guild not found in the cache."),
Self::RoleNotFound => f.write_str("Role not found in the cache."),
Self::MemberNotFound => f.write_str("Member not found in the cache."),
Self::ChannelNotFound => f.write_str("Channel not found in the cache."),
Self::Hierarchy => f.write_str("Role hierarchy prevents this action."),
Self::InvalidChannelType => f.write_str("The channel cannot perform the action."),
Self::InvalidPermissions {
..
} => f.write_str("Invalid permissions."),
Self::InvalidUser => f.write_str("The current user cannot perform the action."),
Self::ItemMissing => f.write_str("The required item is missing from the cache."),
Self::WrongGuild => f.write_str("Provided member or channel is from the wrong guild."),
Self::MessageTooLong(_) => f.write_str("Message too large."),
Self::MessageAlreadyCrossposted => f.write_str("Message already crossposted."),
Self::CannotCrosspostMessage => f.write_str("Cannot crosspost this message type."),
Self::MessagingBot => f.write_str("Attempted to message another bot user."),
Self::NameTooShort => f.write_str("Name is under the character limit."),
Self::NameTooLong => f.write_str("Name is over the character limit."),
Self::NotAuthor => f.write_str("The bot is not author of this message."),
Self::NoTokenSet => f.write_str("Token is not set."),
Self::DeleteNitroSticker => f.write_str("Cannot delete an official sticker."),
Self::NoStickerFileSet => f.write_str("Sticker file is not set."),
Self::StickerAmount => f.write_str("Too many stickers in a message."),
Self::CannotEditVoiceMessage => f.write_str("Cannot edit voice message."),
}
}
}
impl StdError for Error {}