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 /// The transport failed while sending a message.
31 #[error("amqp publish error to '{address}': {source}")]
32 Publish {
33 /// The address the message was published to.
34 address: String,
35 /// The client's send failure.
36 #[source]
37 source: Box<dyn StdError + Send + Sync>,
38 },
39
40 /// The peer settled an outgoing message with a non-accepted outcome (rejected, released, or
41 /// modified), so the message is not on the broker.
42 #[error("amqp publish to '{address}' not accepted: {outcome}")]
43 PublishNotAccepted {
44 /// The address the message was published to.
45 address: String,
46 /// A description of the peer's outcome, including the error condition when one was
47 /// carried.
48 outcome: String,
49 },
50
51 /// The transport failed while receiving a message.
52 #[error("amqp receive error on '{address}': {source}")]
53 Receive {
54 /// The source address of the subscription.
55 address: String,
56 /// The client's receive failure.
57 #[source]
58 source: Box<dyn StdError + Send + Sync>,
59 },
60
61 /// A delivery arrived whose body the crate cannot expose as bytes (an `AMQP` value section
62 /// that is neither binary nor a string).
63 #[error("amqp delivery on '{address}' has an unsupported body section")]
64 UnsupportedBody {
65 /// The source address of the subscription.
66 address: String,
67 },
68
69 /// A request/reply round trip did not produce a reply within the caller's timeout.
70 #[error("amqp request timed out")]
71 RequestTimeout,
72
73 /// The handle is used before `connect` filled the shared connection, or after `shutdown`.
74 #[error("amqp broker is not connected")]
75 NotConnected,
76
77 /// A subscription descriptor is invalid.
78 #[error("invalid amqp address: {0}")]
79 InvalidAddress(String),
80
81 /// A transaction operation was invoked in a state that cannot serve it.
82 #[cfg(feature = "transaction")]
83 #[error("amqp transaction error: {0}")]
84 Transaction(String),
85}
86
87/// Boxes a client error into the crate's `Box<dyn StdError>` source form.
88pub(crate) fn box_err<E>(err: E) -> Box<dyn StdError + Send + Sync>
89where
90 E: StdError + Send + Sync + 'static,
91{
92 Box::new(err)
93}