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    /// Reflection error
24    ReflectError(facet_reflect::ReflectError),
25}
26
27impl From<facet_reflect::ReflectError> for Error {
28    fn from(err: facet_reflect::ReflectError) -> Self {
29        Self::ReflectError(err)
30    }
31}
32
33impl fmt::Display for Error {
34    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35        match self {
36            Error::UnexpectedType => write!(f, "Unexpected MessagePack type"),
37            Error::InsufficientData => write!(f, "Insufficient data to decode"),
38            Error::InvalidData => write!(f, "Invalid MessagePack data"),
39            Error::UnknownField(field) => write!(f, "Unknown field: {}", field),
40            Error::MissingField(field) => write!(f, "Missing required field: {}", field),
41            Error::IntegerOverflow => write!(f, "Integer value too large for target type"),
42            Error::UnsupportedShape(shape) => {
43                write!(f, "Unsupported shape for deserialization: {}", shape)
44            }
45            Error::UnsupportedType(typ) => {
46                write!(f, "Unsupported type for deserialization: {}", typ)
47            }
48            Error::ReflectError(err) => {
49                write!(f, "Reflection error: {}", err)
50            }
51        }
52    }
53}
54
55impl std::error::Error for Error {}