ruststream_zeromq/error.rs
1//! The crate-level error type.
2
3use std::error::Error as StdError;
4
5/// Errors returned by the `ZeroMQ` transport.
6///
7/// One enum for the whole crate, variants by source, per the `RustStream` broker conventions.
8/// The wrapped sources are boxed `std` errors so the public API does not leak the
9/// implementation's error types.
10#[derive(Debug, thiserror::Error)]
11#[non_exhaustive]
12pub enum ZmqError {
13 /// Binding or connecting a socket failed.
14 #[error("zeromq endpoint error on '{endpoint}': {source}")]
15 Endpoint {
16 /// The endpoint the socket targeted.
17 endpoint: String,
18 /// The implementation's failure.
19 #[source]
20 source: Box<dyn StdError + Send + Sync>,
21 },
22
23 /// Sending failed (no connected peer after the retry window, or the transport failed).
24 #[error("zeromq send error to '{name}': {reason}")]
25 Send {
26 /// The message name the send targeted.
27 name: String,
28 /// The failure reason.
29 reason: String,
30 },
31
32 /// Receiving failed.
33 #[error("zeromq receive error: {0}")]
34 Receive(String),
35
36 /// A peer sent frames that do not follow the documented wire layout.
37 #[error("zeromq wire error: {0}")]
38 Wire(String),
39
40 /// A request did not produce a reply within the caller's timeout.
41 #[error("zeromq request timed out")]
42 RequestTimeout,
43
44 /// The handle is used before `connect` filled the shared state, or after `shutdown`.
45 #[error("zeromq transport is not connected")]
46 NotConnected,
47
48 /// An endpoint or descriptor is invalid.
49 #[error("invalid zeromq descriptor: {0}")]
50 Invalid(String),
51}
52
53/// Boxes an implementation error into the crate's `Box<dyn StdError>` source form.
54pub(crate) fn box_err<E>(err: E) -> Box<dyn StdError + Send + Sync>
55where
56 E: StdError + Send + Sync + 'static,
57{
58 Box::new(err)
59}