simdjson_rust/
error.rs

1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, SimdJsonError>;
4
5#[derive(Debug, Error)]
6pub enum SimdJsonError {
7    #[error("This parser can't support a document that big")]
8    Capacity,
9
10    #[error("Error allocating memory, we're most likely out of memory")]
11    MemAlloc,
12
13    #[error("Something went wrong while writing to the tape")]
14    TapeError,
15
16    #[error("The JSON document was too deep (too many nested objects and arrays)")]
17    DepthError,
18
19    #[error("Problem while parsing a string")]
20    StringError,
21
22    #[error("Problem while parsing an atom starting with the letter 't'")]
23    TAtomError,
24
25    #[error("Problem while parsing an atom starting with the letter 'f'")]
26    FAtomError,
27
28    #[error("Problem while parsing an atom starting with the letter 'n'")]
29    NAtomError,
30
31    #[error("Problem while parsing a number")]
32    NumberError,
33
34    #[error("The input is not valid UTF-8")]
35    Utf8Error,
36
37    #[error("Uninitialized")]
38    Uninitialized,
39
40    #[error("Empty: no JSON found")]
41    Empty,
42
43    #[error("Within strings, some characters must be escaped, we found unescaped characters")]
44    UnescapedChars,
45
46    #[error("A string is opened, but never closed.")]
47    UnclosedString,
48
49    #[error(
50        "simdjson does not have an implementation supported by this CPU architecture (perhaps \
51         it's a non-SIMD CPU?)."
52    )]
53    UnsupportedArchitecture,
54
55    #[error("The JSON element does not have the requested type.")]
56    IncorrectType,
57
58    #[error("The JSON number is too large or too small to fit within the requested type.")]
59    NumberOutOfRange,
60
61    #[error("Attempted to access an element of a JSON array that is beyond its length.")]
62    IndexOutOfBounds,
63
64    #[error("The JSON field referenced does not exist in this object.")]
65    NoSuchField,
66
67    #[error("Error reading the file.")]
68    IoError,
69
70    #[error("Invalid JSON pointer syntax.")]
71    InvalidJsonPointer,
72
73    #[error("Invalid URI fragment syntax.")]
74    InvalidUriFragment,
75
76    #[error("todo")]
77    UnexpectedError,
78
79    #[error("todo")]
80    ParserInUse,
81
82    #[error("todo")]
83    OutOfOrderIteration,
84
85    #[error("todo")]
86    InsufficientPadding,
87
88    #[error("todo")]
89    IncompleteArrayOrObject,
90
91    #[error("todo")]
92    ScalarDocumentAsValue,
93
94    #[error("todo")]
95    OutOfBounds,
96
97    #[error("todo")]
98    TailingContent,
99
100    #[error("todo")]
101    NumErrorCodes,
102
103    #[error("todo")]
104    StdIoError(#[from] std::io::Error),
105}
106
107impl From<i32> for SimdJsonError {
108    fn from(error_code: i32) -> Self {
109        match error_code {
110            1 => SimdJsonError::Capacity,
111            2 => SimdJsonError::MemAlloc,
112            3 => SimdJsonError::TapeError,
113            4 => SimdJsonError::DepthError,
114            5 => SimdJsonError::StringError,
115            6 => SimdJsonError::TAtomError,
116            7 => SimdJsonError::FAtomError,
117            8 => SimdJsonError::NAtomError,
118            9 => SimdJsonError::NumberError,
119            10 => SimdJsonError::Utf8Error,
120            11 => SimdJsonError::Uninitialized,
121            12 => SimdJsonError::Empty,
122            13 => SimdJsonError::UnescapedChars,
123            14 => SimdJsonError::UnclosedString,
124            15 => SimdJsonError::UnsupportedArchitecture,
125            16 => SimdJsonError::IncorrectType,
126            17 => SimdJsonError::NumberOutOfRange,
127            18 => SimdJsonError::IndexOutOfBounds,
128            19 => SimdJsonError::NoSuchField,
129            20 => SimdJsonError::IoError,
130            21 => SimdJsonError::InvalidJsonPointer,
131            22 => SimdJsonError::InvalidUriFragment,
132            23 => SimdJsonError::UnexpectedError,
133            24 => SimdJsonError::ParserInUse,
134            25 => SimdJsonError::OutOfOrderIteration,
135            26 => SimdJsonError::InsufficientPadding,
136            27 => SimdJsonError::IncompleteArrayOrObject,
137            28 => SimdJsonError::ScalarDocumentAsValue,
138            29 => SimdJsonError::OutOfBounds,
139            30 => SimdJsonError::TailingContent,
140            31 => SimdJsonError::NumErrorCodes,
141            x => panic!("Unknown error code: {}", x),
142        }
143    }
144}