1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Error type returned by NATS broker operations.
use std::error::Error as StdError;
use thiserror::Error;
/// Errors surfaced by the NATS broker implementation.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum NatsError {
/// Failed to establish or use the underlying `async-nats` connection.
#[error("nats connection error: {0}")]
Connect(#[source] Box<dyn StdError + Send + Sync>),
/// Failed to publish a message to the broker.
#[error("nats publish error: {0}")]
Publish(#[source] Box<dyn StdError + Send + Sync>),
/// Failed to subscribe to the requested subject.
#[error("nats subscribe error: {0}")]
Subscribe(#[source] Box<dyn StdError + Send + Sync>),
/// JetStream-specific operation failed (consumer creation, publish acknowledgement, ack).
#[error("nats jetstream error: {0}")]
JetStream(#[source] Box<dyn StdError + Send + Sync>),
/// Draining the connection during
/// [`shutdown`](ruststream::ConnectedBroker::shutdown) failed.
#[error("nats shutdown error: {0}")]
Shutdown(#[source] Box<dyn StdError + Send + Sync>),
/// A request / reply operation timed out before a reply was received.
#[error("nats request timed out")]
RequestTimeout,
/// A publisher aliasing the connection was used after the broker shut down.
///
/// The lifecycle ladder makes misuse through the owner's handle a compile error:
/// [`ConnectedBroker::shutdown`](ruststream::ConnectedBroker::shutdown) consumes the connected
/// broker. Publishers paired off it earlier keep aliasing the closed connection, so their
/// operations report this instead of silently succeeding against a dead connection.
#[error("nats connection is closed; cannot reach {subject}")]
Closed {
/// The subject the closed publisher was asked to reach.
subject: String,
},
/// The supplied [`crate::SubscribeOptions`] combine fields in a way the broker cannot honour
/// (for example `durable(_)` without `jetstream(_)`, or `queue_group(_)` together with
/// `jetstream(_)`).
#[error("invalid subscribe options: {0}")]
InvalidOptions(String),
}