1use std::io;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum MqttError {
6 #[error("I/O error: {0}")]
7 Io(#[from] io::Error),
8
9 #[error("Malformed packet: {0}")]
10 MalformedPacket(&'static str),
11
12 #[error("Protocol error: {0}")]
13 ProtocolError(String),
14
15 #[error("Unsupported protocol version")]
16 UnsupportedVersion,
17
18 #[error("Payload too large: {size} bytes exceeds limit of {limit} bytes")]
19 PayloadTooLarge { size: usize, limit: usize },
20}
21
22impl From<MqttError> for io::Error {
23 fn from(err: MqttError) -> Self {
24 match err {
25 MqttError::Io(e) => e,
26 other => io::Error::new(io::ErrorKind::InvalidData, other.to_string()),
27 }
28 }
29}