1use core::fmt;
2
3use facet_reflect::ReflectError;
4
5#[derive(Debug)]
6#[non_exhaustive]
7pub enum Error<'shape> {
9 UnexpectedType,
11 InsufficientData,
13 InvalidData,
15 UnknownField(String),
17 MissingField(String),
19 IntegerOverflow,
21 UnsupportedShape(String),
23 UnsupportedType(String),
25 NotImplemented(String),
27 ReflectError(ReflectError<'shape>),
29 InvalidEnum(String),
31}
32
33impl<'shape> From<ReflectError<'shape>> for Error<'shape> {
34 fn from(err: ReflectError<'shape>) -> Self {
35 Self::ReflectError(err)
36 }
37}
38
39impl fmt::Display for Error<'_> {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 match self {
42 Error::UnexpectedType => write!(f, "Unexpected MessagePack type"),
43 Error::InsufficientData => write!(f, "Insufficient data to decode"),
44 Error::InvalidData => write!(f, "Invalid MessagePack data"),
45 Error::UnknownField(field) => write!(f, "Unknown field: {}", field),
46 Error::MissingField(field) => write!(f, "Missing required field: {}", field),
47 Error::IntegerOverflow => write!(f, "Integer value too large for target type"),
48 Error::UnsupportedShape(shape) => {
49 write!(f, "Unsupported shape for deserialization: {}", shape)
50 }
51 Error::UnsupportedType(typ) => {
52 write!(f, "Unsupported type for deserialization: {}", typ)
53 }
54 Error::NotImplemented(feature) => {
55 write!(f, "Feature not yet implemented: {}", feature)
56 }
57 Error::ReflectError(err) => {
58 write!(f, "Reflection error: {}", err)
59 }
60 Error::InvalidEnum(message) => {
61 write!(f, "Invalid enum variant: {}", message)
62 }
63 }
64 }
65}
66
67impl<'shape> std::error::Error for Error<'shape> {}