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, the topic is not one a publish can name
32    /// (empty, or carrying a wildcard), or the topic or a header is not text an MQTT string
33    /// carries (not UTF-8, or holding a control character or a Unicode non-character).
34    #[error("mqtt publish error to '{topic}': {reason}")]
35    Publish {
36        /// The topic the message targeted.
37        topic: String,
38        /// The failure reason.
39        reason: String,
40    },
41
42    /// The handle is used before `connect` filled the shared connection, or after `shutdown`.
43    #[error("mqtt broker is not connected")]
44    NotConnected,
45
46    /// A broker option or subscription descriptor is invalid.
47    #[error("invalid mqtt descriptor: {0}")]
48    Invalid(String),
49}