ruststream_pulsar/error.rs
1//! The crate-level error type.
2
3use std::error::Error as StdError;
4
5/// Errors returned by the Apache Pulsar broker.
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 client's
9/// error types.
10#[derive(Debug, thiserror::Error)]
11#[non_exhaustive]
12pub enum PulsarError {
13 /// Establishing the client connection failed.
14 #[error("pulsar connection error: {0}")]
15 Connect(#[source] Box<dyn StdError + Send + Sync>),
16
17 /// Creating a consumer failed.
18 #[error("pulsar subscribe error on '{topic}': {source}")]
19 Subscribe {
20 /// The topic (or pattern) the subscription targeted.
21 topic: String,
22 /// The client's failure.
23 #[source]
24 source: Box<dyn StdError + Send + Sync>,
25 },
26
27 /// The consumer stream failed or ended permanently.
28 #[error("pulsar receive error on '{topic}': {source}")]
29 Receive {
30 /// The topic (or pattern) of the subscription.
31 topic: String,
32 /// The client's failure.
33 #[source]
34 source: Box<dyn StdError + Send + Sync>,
35 },
36
37 /// Creating a producer or sending a message failed.
38 #[error("pulsar publish error to '{topic}': {source}")]
39 Publish {
40 /// The topic the message targeted.
41 topic: String,
42 /// The client's failure.
43 #[source]
44 source: Box<dyn StdError + Send + Sync>,
45 },
46
47 /// The handle is used before `connect` filled the shared connection, or after `shutdown`.
48 #[error("pulsar broker is not connected")]
49 NotConnected,
50
51 /// A topic name or subscription descriptor is invalid.
52 #[error("invalid pulsar descriptor: {0}")]
53 Invalid(String),
54}
55
56/// Boxes a client error into the crate's `Box<dyn StdError>` source form.
57pub(crate) fn box_err<E>(err: E) -> Box<dyn StdError + Send + Sync>
58where
59 E: StdError + Send + Sync + 'static,
60{
61 Box::new(err)
62}