facet_msgpack/
errors.rs

1use core::fmt;
2
3#[derive(Debug)]
4#[non_exhaustive]
5/// Errors that can occur during MessagePack encoding/decoding operations
6pub enum Error {
7    /// Encountered a MessagePack type that doesn't match the expected type
8    UnexpectedType,
9    /// Not enough data available to decode a complete MessagePack value
10    InsufficientData,
11    /// The MessagePack data is malformed or corrupted
12    InvalidData,
13    /// Encountered a field name that isn't recognized
14    UnknownField(String),
15    /// Required field is missing from the input
16    MissingField(String),
17    /// Integer value is too large for the target type
18    IntegerOverflow,
19    /// Shape is not supported for deserialization
20    UnsupportedShape(String),
21    /// Type is not supported for deserialization
22    UnsupportedType(String),
23}
24
25impl fmt::Display for Error {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27        match self {
28            Error::UnexpectedType => write!(f, "Unexpected MessagePack type"),
29            Error::InsufficientData => write!(f, "Insufficient data to decode"),
30            Error::InvalidData => write!(f, "Invalid MessagePack data"),
31            Error::UnknownField(field) => write!(f, "Unknown field: {}", field),
32            Error::MissingField(field) => write!(f, "Missing required field: {}", field),
33            Error::IntegerOverflow => write!(f, "Integer value too large for target type"),
34            Error::UnsupportedShape(shape) => {
35                write!(f, "Unsupported shape for deserialization: {}", shape)
36            }
37            Error::UnsupportedType(typ) => {
38                write!(f, "Unsupported type for deserialization: {}", typ)
39            }
40        }
41    }
42}
43
44impl std::error::Error for Error {}