evx 0.1.0

A type-safe event bus for domain events, CQRS, Redis Pub/Sub, and durable work queues
Documentation
//! Error types returned by Evx APIs.

use core::fmt;
use std::sync::Arc;

#[derive(Debug, Clone)]
/// Errors produced while serializing, routing, handling, or shutting down
/// messages.
pub enum EventError {
    /// A message could not be serialized.
    Serialization(String),
    /// A message could not be deserialized.
    Deserialization(String),
    /// A broker could not publish or process a message.
    Publish(String),
    /// A handler could not be registered or a queue subscription failed.
    Subscription(String),
    /// A broker could not shut down cleanly.
    Shutdown(String),
    /// A request did not complete before its deadline.
    Timeout(String),
    /// Carries an application-level error from a command handler back to the caller.
    /// The handler wraps its domain error (e.g. `AppError`) so the presentation layer
    /// can downcast and convert it directly to an HTTP response.
    Application(Arc<dyn std::error::Error + Send + Sync>),
}

impl fmt::Display for EventError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Serialization(msg) => write!(f, "serialization error: {msg}"),
            Self::Deserialization(msg) => write!(f, "deserialization error: {msg}"),
            Self::Publish(msg) => write!(f, "publish error: {msg}"),
            Self::Subscription(msg) => write!(f, "subscription error: {msg}"),
            Self::Shutdown(msg) => write!(f, "shutdown error: {msg}"),
            Self::Timeout(msg) => write!(f, "timeout: {msg}"),
            Self::Application(msg) => write!(f, "application error: {msg}"),
        }
    }
}

impl std::error::Error for EventError {}