simdjson  3.11.0
Ridiculously Fast JSON
error.h
1 #ifndef SIMDJSON_ERROR_H
2 #define SIMDJSON_ERROR_H
3 
4 #include "simdjson/base.h"
5 
6 #include <string>
7 #include <ostream>
8 
9 namespace simdjson {
10 
19 enum error_code {
20  SUCCESS = 0,
52  NUM_ERROR_CODES
53 };
54 
72 inline const char *error_message(error_code error) noexcept;
73 
77 inline std::ostream& operator<<(std::ostream& out, error_code error) noexcept;
78 
82 struct simdjson_error : public std::exception {
87  simdjson_error(error_code error) noexcept : _error{error} { }
89  const char *what() const noexcept override { return error_message(error()); }
91  error_code error() const noexcept { return _error; }
92 private:
94  error_code _error;
95 };
96 
97 namespace internal {
98 
119 template<typename T>
120 struct simdjson_result_base : protected std::pair<T, error_code> {
121 
125  simdjson_inline simdjson_result_base() noexcept;
126 
130  simdjson_inline simdjson_result_base(error_code error) noexcept;
131 
135  simdjson_inline simdjson_result_base(T &&value) noexcept;
136 
140  simdjson_inline simdjson_result_base(T &&value, error_code error) noexcept;
141 
148  simdjson_inline void tie(T &value, error_code &error) && noexcept;
149 
155  simdjson_inline error_code get(T &value) && noexcept;
156 
160  simdjson_inline error_code error() const noexcept;
161 
162 #if SIMDJSON_EXCEPTIONS
163 
169  simdjson_inline T& value() & noexcept(false);
170 
176  simdjson_inline T&& value() && noexcept(false);
177 
183  simdjson_inline T&& take_value() && noexcept(false);
184 
190  simdjson_inline operator T&&() && noexcept(false);
191 #endif // SIMDJSON_EXCEPTIONS
192 
197  simdjson_inline const T& value_unsafe() const& noexcept;
198 
203  simdjson_inline T&& value_unsafe() && noexcept;
204 
205 }; // struct simdjson_result_base
206 
207 } // namespace internal
208 
214 template<typename T>
215 struct simdjson_result : public internal::simdjson_result_base<T> {
219  simdjson_inline simdjson_result() noexcept;
223  simdjson_inline simdjson_result(T &&value) noexcept;
227  simdjson_inline simdjson_result(error_code error_code) noexcept;
231  simdjson_inline simdjson_result(T &&value, error_code error) noexcept;
232 
239  simdjson_inline void tie(T &value, error_code &error) && noexcept;
240 
246  simdjson_warn_unused simdjson_inline error_code get(T &value) && noexcept;
247 
251  simdjson_inline error_code error() const noexcept;
252 
253 #if SIMDJSON_EXCEPTIONS
254 
260  simdjson_inline T& value() & noexcept(false);
261 
267  simdjson_inline T&& value() && noexcept(false);
268 
274  simdjson_inline T&& take_value() && noexcept(false);
275 
281  simdjson_inline operator T&&() && noexcept(false);
282 #endif // SIMDJSON_EXCEPTIONS
283 
288  simdjson_inline const T& value_unsafe() const& noexcept;
289 
294  simdjson_inline T&& value_unsafe() && noexcept;
295 
296 }; // struct simdjson_result
297 
298 #if SIMDJSON_EXCEPTIONS
299 
300 template<typename T>
301 inline std::ostream& operator<<(std::ostream& out, simdjson_result<T> value) { return out << value.value(); }
302 #endif // SIMDJSON_EXCEPTIONS
303 
304 #ifndef SIMDJSON_DISABLE_DEPRECATED_API
308 using ErrorValues [[deprecated("This is an alias and will be removed, use error_code instead")]] = error_code;
309 
313 [[deprecated("Error codes should be stored and returned as `error_code`, use `error_message()` instead.")]]
314 inline const std::string error_message(int error) noexcept;
315 #endif // SIMDJSON_DISABLE_DEPRECATED_API
316 } // namespace simdjson
317 
318 #endif // SIMDJSON_ERROR_H
The top level simdjson namespace, containing everything the library provides.
Definition: base.h:8
std::ostream & operator<<(std::ostream &out, error_code error) noexcept
Write the error message to the output stream.
Definition: error-inl.h:35
const char * error_message(error_code error) noexcept
It is the convention throughout the code that the macro SIMDJSON_DEVELOPMENT_CHECKS determines whethe...
Definition: error-inl.h:20
error_code
All possible errors returned by simdjson.
Definition: error.h:19
@ SCALAR_DOCUMENT_AS_VALUE
A scalar document is treated as a value.
Definition: error.h:49
@ DEPTH_ERROR
Your document exceeds the user-specified depth limitation.
Definition: error.h:24
@ UNCLOSED_STRING
missing quote at the end
Definition: error.h:35
@ INCORRECT_TYPE
JSON element has a different type than user expected.
Definition: error.h:37
@ CAPACITY
This parser can't support a document that big.
Definition: error.h:21
@ OUT_OF_ORDER_ITERATION
tried to iterate an array or object out of order (checked when SIMDJSON_DEVELOPMENT_CHECKS=1)
Definition: error.h:46
@ UTF8_ERROR
the input is not valid UTF-8
Definition: error.h:31
@ OUT_OF_BOUNDS
Attempted to access location outside of document.
Definition: error.h:50
@ TAPE_ERROR
Something went wrong, this is a generic error.
Definition: error.h:23
@ NO_SUCH_FIELD
JSON field not found in object.
Definition: error.h:40
@ UNSUPPORTED_ARCHITECTURE
unsupported architecture
Definition: error.h:36
@ N_ATOM_ERROR
Problem while parsing an atom starting with the letter 'n'.
Definition: error.h:28
@ EMPTY
no structural element found
Definition: error.h:33
@ INVALID_URI_FRAGMENT
Invalid URI fragment.
Definition: error.h:43
@ INDEX_OUT_OF_BOUNDS
JSON array index too large.
Definition: error.h:39
@ NUMBER_OUT_OF_RANGE
JSON number does not fit in 64 bits.
Definition: error.h:38
@ STRING_ERROR
Problem while parsing a string.
Definition: error.h:25
@ MEMALLOC
Error allocating memory, most likely out of memory.
Definition: error.h:22
@ SUCCESS
No error.
Definition: error.h:20
@ T_ATOM_ERROR
Problem while parsing an atom starting with the letter 't'.
Definition: error.h:26
@ TRAILING_CONTENT
Unexpected trailing content in the JSON input.
Definition: error.h:51
@ INCOMPLETE_ARRAY_OR_OBJECT
The document ends early.
Definition: error.h:48
@ UNEXPECTED_ERROR
indicative of a bug in simdjson
Definition: error.h:44
@ UNINITIALIZED
unknown error, or uninitialized document
Definition: error.h:32
@ UNESCAPED_CHARS
found unescaped characters in a string.
Definition: error.h:34
@ IO_ERROR
Error reading a file.
Definition: error.h:41
@ NUMBER_ERROR
Problem while parsing a number.
Definition: error.h:29
@ BIGINT_ERROR
The integer value exceeds 64 bits.
Definition: error.h:30
@ F_ATOM_ERROR
Problem while parsing an atom starting with the letter 'f'.
Definition: error.h:27
@ PARSER_IN_USE
parser is already in use.
Definition: error.h:45
@ INSUFFICIENT_PADDING
The JSON doesn't have enough padding for simdjson to safely parse it.
Definition: error.h:47
@ INVALID_JSON_POINTER
Invalid JSON pointer syntax.
Definition: error.h:42
Exception thrown when an exception-supporting simdjson method is called.
Definition: error.h:82
const char * what() const noexcept override
The error message.
Definition: error.h:89
error_code error() const noexcept
The error code.
Definition: error.h:91
simdjson_error(error_code error) noexcept
Create an exception from a simdjson error code.
Definition: error.h:87
The result of a simdjson operation that could fail.
Definition: error.h:215
simdjson_inline const T & value_unsafe() const &noexcept
Get the result value.
simdjson_inline T && value() &&noexcept(false)
Take the result value (move it).
simdjson_inline T & value() &noexcept(false)
Get the result value.