use std::fmt;
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[non_exhaustive]
pub enum Channel {
Mail,
Database,
Broadcast,
}
impl fmt::Display for Channel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let name = match self {
Self::Mail => "mail",
Self::Database => "database",
Self::Broadcast => "broadcast",
};
f.write_str(name)
}
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum NotificationError {
#[error("notification: the {channel} channel is not configured on this notifier")]
NotConfigured {
channel: Channel,
},
#[error("notification: the mail channel was requested for {key}, which has no email address")]
NoAddress {
key: String,
},
#[error("notification: {source}")]
Mail {
#[from]
source: crate::mail::MailSendError,
},
#[cfg(feature = "notifications-db")]
#[error("notification: {source}")]
Database {
#[from]
source: sqlx::Error,
},
#[cfg(feature = "notifications-db")]
#[error("notification: a stored notification could not be decoded: {0}")]
Decode(String),
#[cfg(feature = "notifications-db")]
#[error("notification: a stored timestamp is out of range: {0}")]
Timestamp(String),
#[cfg(feature = "notifications-db")]
#[error("notification: {attempts} random ids were all taken")]
IdCollision {
attempts: u32,
},
#[cfg(feature = "notifications-db")]
#[error("notification: the OS randomness source is unavailable")]
Entropy,
#[cfg(feature = "notifications-broadcast")]
#[error("notification: a broadcast payload could not be serialised: {0}")]
Encode(String),
#[cfg(feature = "notifications-queue")]
#[error("notification: {source}")]
Queue {
#[from]
source: crate::jobs::EnqueueError,
},
#[cfg(feature = "notifications-queue")]
#[error("notification: the mail channel was queued, but this notifier has no queue")]
QueueNotConfigured,
}