#[derive(Debug)]
pub enum MessageError {
SendFailed(String),
ChannelClosed,
Cancelled,
OtherError(String),
}
impl std::fmt::Display for MessageError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::SendFailed(msg) => write!(f, "Failed to send message: {msg}"),
Self::ChannelClosed => write!(f, "Recipient channel is closed"),
Self::Cancelled => write!(f, "Send operation was cancelled"),
Self::OtherError(msg) => write!(f, "Error: {msg}"),
}
}
}
impl std::error::Error for MessageError {}
impl<T> From<tokio::sync::mpsc::error::SendError<T>> for MessageError {
fn from(_: tokio::sync::mpsc::error::SendError<T>) -> Self {
Self::SendFailed("Channel closed".into())
}
}