intercom-rs 1.1.1

A fully typed async wrapper for NATS with JetStream support
Documentation
//! Error types for the intercom library.

use thiserror::Error;

/// The main error type for intercom operations.
#[derive(Error, Debug)]
pub enum Error {
    /// Error from the underlying NATS client.
    #[error("NATS error: {0}")]
    Nats(#[from] async_nats::Error),

    /// Error connecting to NATS.
    #[error("Connection error: {0}")]
    Connect(#[from] async_nats::ConnectError),

    /// Error publishing a message.
    #[error("Publish error: {0}")]
    Publish(#[from] async_nats::PublishError),

    /// Error subscribing to a subject.
    #[error("Subscribe error: {0}")]
    Subscribe(#[from] async_nats::SubscribeError),

    /// Error serializing a message with MessagePack.
    #[cfg(feature = "msgpack")]
    #[error("MessagePack serialization error: {0}")]
    MsgPackSerialize(#[from] rmp_serde::encode::Error),

    /// Error deserializing a message with MessagePack.
    #[cfg(feature = "msgpack")]
    #[error("MessagePack deserialization error: {0}")]
    MsgPackDeserialize(#[from] rmp_serde::decode::Error),

    /// Error serializing/deserializing a message with JSON.
    #[cfg(feature = "json")]
    #[error("JSON error: {0}")]
    Json(#[from] serde_json::Error),

    /// Error from JetStream operations.
    #[error("JetStream error: {0}")]
    JetStream(String),

    /// Error creating a JetStream context.
    #[error("JetStream context error: {0}")]
    JetStreamContext(#[from] async_nats::jetstream::context::CreateStreamError),

    /// Error creating a JetStream consumer.
    #[error("JetStream consumer error: {0}")]
    JetStreamConsumer(String),

    /// Error with JetStream stream operations.
    #[error("JetStream stream error: {0}")]
    JetStreamStream(String),

    /// Request error.
    #[error("Request error: {0}")]
    Request(#[from] async_nats::RequestError),

    /// Timeout error.
    #[error("Timeout")]
    Timeout,

    /// The subscriber was closed.
    #[error("Subscriber closed")]
    SubscriberClosed,

    /// The publisher was closed.
    #[error("Publisher closed")]
    PublisherClosed,

    /// Invalid configuration.
    #[error("Invalid configuration: {0}")]
    InvalidConfig(String),
}

/// Result type alias for intercom operations.
pub type Result<T> = std::result::Result<T, Error>;