1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use thiserror::Error;

pub type Result<T> = std::result::Result<T, SimdJsonError>;

#[derive(Debug, Error)]
pub enum SimdJsonError {
    #[error("This parser can't support a document that big")]
    Capacity,

    #[error("Error allocating memory, we're most likely out of memory")]
    MemAlloc,

    #[error("Something went wrong while writing to the tape")]
    TapeError,

    #[error("The JSON document was too deep (too many nested objects and arrays)")]
    DepthError,

    #[error("Problem while parsing a string")]
    StringError,

    #[error("Problem while parsing an atom starting with the letter 't'")]
    TAtomError,

    #[error("Problem while parsing an atom starting with the letter 'f'")]
    FAtomError,

    #[error("Problem while parsing an atom starting with the letter 'n'")]
    NAtomError,

    #[error("Problem while parsing a number")]
    NumberError,

    #[error("The input is not valid UTF-8")]
    Utf8Error,

    #[error("Uninitialized")]
    Uninitialized,

    #[error("Empty: no JSON found")]
    Empty,

    #[error("Within strings, some characters must be escaped, we found unescaped characters")]
    UnescapedChars,

    #[error("A string is opened, but never closed.")]
    UnclosedString,

    #[error(
        "simdjson does not have an implementation supported by this CPU architecture (perhaps \
         it's a non-SIMD CPU?)."
    )]
    UnsupportedArchitecture,

    #[error("The JSON element does not have the requested type.")]
    IncorrectType,

    #[error("The JSON number is too large or too small to fit within the requested type.")]
    NumberOutOfRange,

    #[error("Attempted to access an element of a JSON array that is beyond its length.")]
    IndexOutOfBounds,

    #[error("The JSON field referenced does not exist in this object.")]
    NoSuchField,

    #[error("Error reading the file.")]
    IoError,

    #[error("Invalid JSON pointer syntax.")]
    InvalidJsonPointer,

    #[error("Invalid URI fragment syntax.")]
    InvalidUriFragment,

    #[error("todo")]
    UnexpectedError,

    #[error("todo")]
    ParserInUse,

    #[error("todo")]
    OutOfOrderIteration,

    #[error("todo")]
    InsufficientPadding,

    #[error("todo")]
    IncompleteArrayOrObject,

    #[error("todo")]
    ScalarDocumentAsValue,

    #[error("todo")]
    OutOfBounds,

    #[error("todo")]
    TailingContent,

    #[error("todo")]
    NumErrorCodes,

    #[error("todo")]
    StdIoError(#[from] std::io::Error),
}

impl From<i32> for SimdJsonError {
    fn from(error_code: i32) -> Self {
        match error_code {
            1 => SimdJsonError::Capacity,
            2 => SimdJsonError::MemAlloc,
            3 => SimdJsonError::TapeError,
            4 => SimdJsonError::DepthError,
            5 => SimdJsonError::StringError,
            6 => SimdJsonError::TAtomError,
            7 => SimdJsonError::FAtomError,
            8 => SimdJsonError::NAtomError,
            9 => SimdJsonError::NumberError,
            10 => SimdJsonError::Utf8Error,
            11 => SimdJsonError::Uninitialized,
            12 => SimdJsonError::Empty,
            13 => SimdJsonError::UnescapedChars,
            14 => SimdJsonError::UnclosedString,
            15 => SimdJsonError::UnsupportedArchitecture,
            16 => SimdJsonError::IncorrectType,
            17 => SimdJsonError::NumberOutOfRange,
            18 => SimdJsonError::IndexOutOfBounds,
            19 => SimdJsonError::NoSuchField,
            20 => SimdJsonError::IoError,
            21 => SimdJsonError::InvalidJsonPointer,
            22 => SimdJsonError::InvalidUriFragment,
            23 => SimdJsonError::UnexpectedError,
            24 => SimdJsonError::ParserInUse,
            25 => SimdJsonError::OutOfOrderIteration,
            26 => SimdJsonError::InsufficientPadding,
            27 => SimdJsonError::IncompleteArrayOrObject,
            28 => SimdJsonError::ScalarDocumentAsValue,
            29 => SimdJsonError::OutOfBounds,
            30 => SimdJsonError::TailingContent,
            31 => SimdJsonError::NumErrorCodes,
            x => panic!("Unknown error code: {}", x),
        }
    }
}