intercom_rs/
error.rs

1//! Error types for the intercom library.
2
3use thiserror::Error;
4
5/// The main error type for intercom operations.
6#[derive(Error, Debug)]
7pub enum Error {
8    /// Error from the underlying NATS client.
9    #[error("NATS error: {0}")]
10    Nats(#[from] async_nats::Error),
11
12    /// Error connecting to NATS.
13    #[error("Connection error: {0}")]
14    Connect(#[from] async_nats::ConnectError),
15
16    /// Error publishing a message.
17    #[error("Publish error: {0}")]
18    Publish(#[from] async_nats::PublishError),
19
20    /// Error subscribing to a subject.
21    #[error("Subscribe error: {0}")]
22    Subscribe(#[from] async_nats::SubscribeError),
23
24    /// Error serializing a message with MessagePack.
25    #[cfg(feature = "msgpack")]
26    #[error("MessagePack serialization error: {0}")]
27    MsgPackSerialize(#[from] rmp_serde::encode::Error),
28
29    /// Error deserializing a message with MessagePack.
30    #[cfg(feature = "msgpack")]
31    #[error("MessagePack deserialization error: {0}")]
32    MsgPackDeserialize(#[from] rmp_serde::decode::Error),
33
34    /// Error serializing/deserializing a message with JSON.
35    #[cfg(feature = "json")]
36    #[error("JSON error: {0}")]
37    Json(#[from] serde_json::Error),
38
39    /// Error from JetStream operations.
40    #[error("JetStream error: {0}")]
41    JetStream(String),
42
43    /// Error creating a JetStream context.
44    #[error("JetStream context error: {0}")]
45    JetStreamContext(#[from] async_nats::jetstream::context::CreateStreamError),
46
47    /// Error creating a JetStream consumer.
48    #[error("JetStream consumer error: {0}")]
49    JetStreamConsumer(String),
50
51    /// Error with JetStream stream operations.
52    #[error("JetStream stream error: {0}")]
53    JetStreamStream(String),
54
55    /// Request error.
56    #[error("Request error: {0}")]
57    Request(#[from] async_nats::RequestError),
58
59    /// Timeout error.
60    #[error("Timeout")]
61    Timeout,
62
63    /// The subscriber was closed.
64    #[error("Subscriber closed")]
65    SubscriberClosed,
66
67    /// The publisher was closed.
68    #[error("Publisher closed")]
69    PublisherClosed,
70
71    /// Invalid configuration.
72    #[error("Invalid configuration: {0}")]
73    InvalidConfig(String),
74}
75
76/// Result type alias for intercom operations.
77pub type Result<T> = std::result::Result<T, Error>;