1use core::fmt;
2
3use super::type_hint::{NumberHint, TypeHint};
4
5crate::macros::implement_error! {
6 pub struct Error;
8}
9
10#[derive(Debug)]
12#[non_exhaustive]
13#[allow(missing_docs)]
14pub(crate) enum ErrorMessage {
15 ArrayOutOfBounds,
16 ExpectedPackValue,
17 ExpectedEmpty(TypeHint),
18 ExpectedBool(TypeHint),
19 ExpectedChar(TypeHint),
20 ExpectedNumber(NumberHint, TypeHint),
21 ExpectedMapValue,
22 ExpectedBytes(TypeHint),
23 ExpectedString(TypeHint),
24 ExpectedStringAsNumber,
25 ExpectedSequence(TypeHint),
26 ExpectedPack(TypeHint),
27 ExpectedMap(TypeHint),
28 ExpectedVariant(TypeHint),
29}
30
31impl fmt::Display for ErrorMessage {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 match self {
34 ErrorMessage::ArrayOutOfBounds => {
35 write!(
36 f,
37 "Value buffer tried to decode array that is out-of-bounds"
38 )
39 }
40 ErrorMessage::ExpectedPackValue => write!(f, "Value buffer expected pack value"),
41 ErrorMessage::ExpectedEmpty(hint) => {
42 write!(f, "Value buffer expected empty, but found {hint}")
43 }
44 ErrorMessage::ExpectedBool(hint) => {
45 write!(f, "Value buffer expected boolean, but found {hint}")
46 }
47 ErrorMessage::ExpectedChar(hint) => {
48 write!(f, "Value buffer expected character, but found {hint}")
49 }
50 ErrorMessage::ExpectedNumber(number, hint) => {
51 write!(f, "Value buffer expected {number}, but found {hint}")
52 }
53 ErrorMessage::ExpectedMapValue => write!(f, "Value buffer expected map value"),
54 ErrorMessage::ExpectedBytes(hint) => {
55 write!(f, "Value buffer expected bytes, but found {hint}")
56 }
57 ErrorMessage::ExpectedString(hint) => {
58 write!(f, "Value buffer expected string, but found {hint}")
59 }
60 ErrorMessage::ExpectedStringAsNumber => {
61 write!(f, "Value buffer expected string containing number")
62 }
63 ErrorMessage::ExpectedSequence(hint) => {
64 write!(f, "Value buffer expected sequence, but found {hint}")
65 }
66 ErrorMessage::ExpectedPack(hint) => {
67 write!(f, "Value buffer expected pack of bytes, but found {hint}")
68 }
69 ErrorMessage::ExpectedMap(hint) => {
70 write!(f, "Value buffer expected map, but found {hint}")
71 }
72 ErrorMessage::ExpectedVariant(hint) => {
73 write!(f, "Value buffer expected variant, but found {hint}")
74 }
75 }
76 }
77}