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