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