use symqtt_codec::QoS;
use symqtt_codec::v5::ReasonCode;
use crate::v5::SessionError;
#[non_exhaustive]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("connection refused: {0:?} {1:?}")]
ConnectRefused(ReasonCode, Option<String>),
#[error("transport I/O: {0}")]
Io(#[from] std::io::Error),
#[error("decode: {0}")]
Decode(#[from] symqtt_codec::DecodeError),
#[error("encode: {0}")]
Encode(#[from] symqtt_codec::EncodeError),
#[error("inflight window full (receive_maximum={0})")]
WindowFull(u16),
#[error("ack timeout")]
Timeout,
#[error("disconnected")]
Disconnected,
#[error("ping timeout")]
PingTimeout,
#[error("session: {0}")]
Session(#[from] SessionError),
#[error("topic alias invalid: {0}")]
TopicAliasInvalid(u16),
#[error("packet too large: size={size} max={max}")]
PacketTooLarge {
size: usize,
max: u32,
},
#[error("server disconnect: {0:?}")]
ServerDisconnect(ReasonCode),
#[error("qos not supported: requested {requested:?} max {max:?}")]
QosNotSupported {
requested: QoS,
max: QoS,
},
#[error("retain not supported")]
RetainNotSupported,
#[error("auth failed: {0:?}")]
AuthFailed(ReasonCode),
#[error("subscription identifiers not supported")]
SubscriptionIdNotSupported,
}
impl Clone for Error {
fn clone(&self) -> Self {
match self {
Self::ConnectRefused(c, s) => Self::ConnectRefused(*c, s.clone()),
Self::Io(e) => Self::Io(std::io::Error::new(e.kind(), e.to_string())),
Self::Decode(e) => Self::Decode(e.clone()),
Self::Encode(e) => Self::Encode(e.clone()),
Self::WindowFull(n) => Self::WindowFull(*n),
Self::Timeout => Self::Timeout,
Self::Disconnected => Self::Disconnected,
Self::PingTimeout => Self::PingTimeout,
Self::Session(e) => Self::Session(e.clone()),
Self::TopicAliasInvalid(a) => Self::TopicAliasInvalid(*a),
Self::PacketTooLarge { size, max } => Self::PacketTooLarge { size: *size, max: *max },
Self::ServerDisconnect(c) => Self::ServerDisconnect(*c),
Self::QosNotSupported { requested, max } => Self::QosNotSupported {
requested: *requested,
max: *max,
},
Self::RetainNotSupported => Self::RetainNotSupported,
Self::AuthFailed(c) => Self::AuthFailed(*c),
Self::SubscriptionIdNotSupported => Self::SubscriptionIdNotSupported,
}
}
}