1use core::fmt;
2
3#[derive(Debug)]
4#[non_exhaustive]
5pub enum Error {
7 UnexpectedType,
9 InsufficientData,
11 InvalidData,
13 UnknownField(String),
15 MissingField(String),
17 IntegerOverflow,
19 UnsupportedShape(String),
21 UnsupportedType(String),
23 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 {}