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 NotImplemented(String),
25 ReflectError(facet_reflect::ReflectError),
27 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 {}