rimu_value/serde/
error.rs

1use std::fmt::Display;
2
3use serde::{de, ser};
4
5#[derive(Debug, Clone, thiserror::Error)]
6pub enum SerdeValueError {
7    #[error("{0}")]
8    Deserialize(String),
9
10    #[error("{0}")]
11    Serialize(String),
12
13    /// EOF while parsing a list.
14    #[error("")]
15    EofWhileParsingList,
16
17    /// EOF while parsing an object.
18    #[error("")]
19    EofWhileParsingObject,
20
21    /// EOF while parsing a string.
22    #[error("")]
23    EofWhileParsingString,
24
25    /// EOF while parsing a JSON value.
26    #[error("")]
27    EofWhileParsingValue,
28
29    /// Expected this character to be a `':'`.
30    #[error("")]
31    ExpectedColon,
32
33    /// Expected this character to be either a `','` or a `']'`.
34    #[error("")]
35    ExpectedListCommaOrEnd,
36
37    /// Expected this character to be either a `','` or a `'}'`.
38    #[error("")]
39    ExpectedObjectCommaOrEnd,
40
41    /// Expected to parse either a `true`, `false`, or a `null`.
42    #[error("")]
43    ExpectedSomeIdent,
44
45    /// Expected this character to start a JSON value.
46    #[error("")]
47    ExpectedSomeValue,
48
49    /// Expected this character to be a `"`.
50    #[error("")]
51    ExpectedDoubleQuote,
52
53    /// Invalid hex escape code.
54    #[error("")]
55    InvalidEscape,
56
57    /// Invalid number.
58    #[error("")]
59    InvalidNumber,
60
61    /// Number is bigger than the maximum value of its type.
62    #[error("")]
63    NumberOutOfRange,
64
65    /// Invalid unicode code point.
66    #[error("")]
67    InvalidUnicodeCodePoint,
68
69    /// Control character found while parsing a string.
70    #[error("")]
71    ControlCharacterWhileParsingString,
72
73    /// Object key is not a string.
74    #[error("")]
75    KeyMustBeAString,
76
77    /// Contents of key were supposed to be a number.
78    #[error("")]
79    ExpectedNumericKey,
80
81    /// Object key is a non-finite float value.
82    #[error("")]
83    FloatKeyMustBeFinite,
84
85    /// Lone leading surrogate in hex escape.
86    #[error("")]
87    LoneLeadingSurrogateInHexEscape,
88
89    /// JSON has a comma after the last value in an array or map.
90    #[error("")]
91    TrailingComma,
92
93    /// JSON has non-whitespace trailing characters after the value.
94    #[error("")]
95    TrailingCharacters,
96
97    /// Unexpected end of hex escape.
98    #[error("")]
99    UnexpectedEndOfHexEscape,
100
101    /// Encountered nesting of JSON maps and arrays more than 128 layers deep.
102    #[error("")]
103    RecursionLimitExceeded,
104}
105
106impl de::Error for SerdeValueError {
107    fn custom<T: Display>(msg: T) -> Self {
108        SerdeValueError::Deserialize(msg.to_string())
109    }
110}
111
112impl ser::Error for SerdeValueError {
113    fn custom<T: Display>(msg: T) -> Self {
114        SerdeValueError::Serialize(msg.to_string())
115    }
116}