ruststream_amqp/error.rs
1//! The crate-level error type.
2
3use std::error::Error as StdError;
4
5/// Errors returned by the AMQP 1.0 broker.
6///
7/// One enum for the whole crate, variants by source, per the `RustStream` broker conventions. The
8/// wrapped sources are boxed `std` errors so the public API does not leak `fe2o3-amqp` types.
9#[derive(Debug, thiserror::Error)]
10#[non_exhaustive]
11pub enum AmqpError {
12 /// Opening the connection (TCP, TLS, SASL, or the AMQP handshake) failed.
13 #[error("amqp connection error: {0}")]
14 Connect(#[source] Box<dyn StdError + Send + Sync>),
15
16 /// Beginning a session on the live connection failed.
17 #[error("amqp session error: {0}")]
18 Session(#[source] Box<dyn StdError + Send + Sync>),
19
20 /// Attaching a link (sender or receiver) failed.
21 #[error("amqp link attach error for '{address}': {source}")]
22 Attach {
23 /// The address the link was attached to.
24 address: String,
25 /// The client's attach failure.
26 #[source]
27 source: Box<dyn StdError + Send + Sync>,
28 },
29
30 /// Closing a link during shutdown failed, so the peer may still consider it attached.
31 #[error("amqp link close error for '{address}': {source}")]
32 Detach {
33 /// The address the link was attached to.
34 address: String,
35 /// The client's detach failure.
36 #[source]
37 source: Box<dyn StdError + Send + Sync>,
38 },
39
40 /// The transport failed while sending a message.
41 #[error("amqp publish error to '{address}': {source}")]
42 Publish {
43 /// The address the message was published to.
44 address: String,
45 /// The client's send failure.
46 #[source]
47 source: Box<dyn StdError + Send + Sync>,
48 },
49
50 /// The peer settled an outgoing message with a non-accepted outcome (rejected, released, or
51 /// modified), so the message is not on the broker.
52 #[error("amqp publish to '{address}' not accepted: {outcome}")]
53 PublishNotAccepted {
54 /// The address the message was published to.
55 address: String,
56 /// A description of the peer's outcome, including the error condition when one was
57 /// carried.
58 outcome: String,
59 },
60
61 /// The transport failed while receiving a message.
62 #[error("amqp receive error on '{address}': {source}")]
63 Receive {
64 /// The source address of the subscription.
65 address: String,
66 /// The client's receive failure.
67 #[source]
68 source: Box<dyn StdError + Send + Sync>,
69 },
70
71 /// A delivery arrived whose body the crate cannot expose as bytes (an `AMQP` value section
72 /// that is neither binary nor a string).
73 #[error("amqp delivery on '{address}' has an unsupported body section")]
74 UnsupportedBody {
75 /// The source address of the subscription.
76 address: String,
77 },
78
79 /// A request/reply round trip did not produce a reply within the caller's timeout.
80 #[error("amqp request timed out")]
81 RequestTimeout,
82
83 /// The handle is used before `connect` filled the shared connection, or after `shutdown`.
84 #[error("amqp broker is not connected")]
85 NotConnected,
86
87 /// A subscription descriptor is invalid.
88 #[error("invalid amqp address: {0}")]
89 InvalidAddress(String),
90
91 /// A transaction operation was invoked in a state that cannot serve it.
92 #[cfg(feature = "transaction")]
93 #[error("amqp transaction error: {0}")]
94 Transaction(String),
95}
96
97/// Boxes a client error into the crate's `Box<dyn StdError>` source form.
98pub(crate) fn box_err<E>(err: E) -> Box<dyn StdError + Send + Sync>
99where
100 E: StdError + Send + Sync + 'static,
101{
102 Box::new(err)
103}