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