Skip to main content

ruststream_rumqttc/
error.rs

1//! The crate-level error type.
2
3use std::error::Error as StdError;
4
5/// Errors returned by the MQTT 5 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 MqttError {
13    /// Establishing the connection failed (transport, TLS, or the broker refused the
14    /// connection with a non-retryable reason).
15    #[error("mqtt connection error: {0}")]
16    Connect(#[source] Box<dyn StdError + Send + Sync>),
17
18    /// Subscribing failed (the broker rejected the filter, or the connection died).
19    #[error("mqtt subscribe error on '{filter}': {reason}")]
20    Subscribe {
21        /// The topic filter the subscription targeted.
22        filter: String,
23        /// The rejection or transport reason.
24        reason: String,
25    },
26
27    /// The connection failed permanently while receiving.
28    #[error("mqtt receive error: {0}")]
29    Receive(String),
30
31    /// Publishing failed (the connection task is gone, or the topic is invalid).
32    #[error("mqtt publish error to '{topic}': {reason}")]
33    Publish {
34        /// The topic the message targeted.
35        topic: String,
36        /// The failure reason.
37        reason: String,
38    },
39
40    /// The handle is used before `connect` filled the shared connection, or after `shutdown`.
41    #[error("mqtt broker is not connected")]
42    NotConnected,
43
44    /// A broker option or subscription descriptor is invalid.
45    #[error("invalid mqtt descriptor: {0}")]
46    Invalid(String),
47}