mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
35 lines
1.2 KiB
Rust
35 lines
1.2 KiB
Rust
use thiserror::Error;
|
|
|
|
/// Errors that can occur in pub/sub, presence, and typing operations.
|
|
#[derive(Debug, Error)]
|
|
pub enum PubSubError {
|
|
/// A Redis command failed.
|
|
#[error("Redis error: {0}")]
|
|
Redis(#[from] redis::RedisError),
|
|
|
|
/// JSON serialization or deserialization failed.
|
|
#[error("Serialization error: {0}")]
|
|
Serialization(#[from] serde_json::Error),
|
|
|
|
/// The broadcast receiver fell behind and dropped messages.
|
|
#[error("Broadcast receiver lagged: {0} messages dropped")]
|
|
BroadcastLagged(u64),
|
|
|
|
/// The pub/sub subscriber task has stopped unexpectedly.
|
|
#[error("Pub/sub subscriber task stopped")]
|
|
SubscriberStopped,
|
|
|
|
/// A Redis channel key could not be parsed as a valid channel ID.
|
|
#[error("Invalid channel key: {0}")]
|
|
InvalidChannelKey(String),
|
|
}
|
|
|
|
impl From<tokio::sync::broadcast::error::RecvError> for PubSubError {
|
|
fn from(e: tokio::sync::broadcast::error::RecvError) -> Self {
|
|
match e {
|
|
tokio::sync::broadcast::error::RecvError::Lagged(n) => PubSubError::BroadcastLagged(n),
|
|
tokio::sync::broadcast::error::RecvError::Closed => PubSubError::SubscriberStopped,
|
|
}
|
|
}
|
|
}
|