platform_value/
error.rs

1use std::fmt::Display;
2
3use thiserror::Error;
4
5#[derive(Error, Clone, Eq, PartialEq, Debug)]
6pub enum Error {
7    #[error("unsupported: {0}")]
8    Unsupported(String),
9
10    #[error("structure error: {0}")]
11    StructureError(String),
12
13    #[error("path error: {0}")]
14    PathError(String),
15
16    #[error("integer out of bounds")]
17    IntegerSizeError,
18
19    #[error("integer parsing")]
20    IntegerParsingError,
21
22    #[error("string decoding error {0}")]
23    StringDecodingError(String),
24
25    #[error("key must be a string")]
26    KeyMustBeAString,
27
28    #[error("byte length not 20 bytes error: {0}")]
29    ByteLengthNot20BytesError(String),
30
31    #[error("byte length not 32 bytes error: {0}")]
32    ByteLengthNot32BytesError(String),
33
34    #[error("byte length not 36 bytes error: {0}")]
35    ByteLengthNot36BytesError(String),
36
37    #[error("serde serialization error: {0}")]
38    SerdeSerializationError(String),
39
40    #[error("serde deserialization error: {0}")]
41    SerdeDeserializationError(String),
42
43    #[error("cbor serialization error: {0}")]
44    CborSerializationError(String),
45}
46
47impl serde::ser::Error for Error {
48    fn custom<T>(msg: T) -> Self
49    where
50        T: Display,
51    {
52        Error::SerdeSerializationError(msg.to_string())
53    }
54}
55
56impl serde::de::Error for Error {
57    fn custom<T>(msg: T) -> Self
58    where
59        T: Display,
60    {
61        Error::SerdeDeserializationError(msg.to_string())
62    }
63}