simdjson  3.6.4
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,
51  NUM_ERROR_CODES
52 };
53 
71 inline const char *error_message(error_code error) noexcept;
72 
76 inline std::ostream& operator<<(std::ostream& out, error_code error) noexcept;
77 
81 struct simdjson_error : public std::exception {
86  simdjson_error(error_code error) noexcept : _error{error} { }
88  const char *what() const noexcept { return error_message(error()); }
90  error_code error() const noexcept { return _error; }
91 private:
93  error_code _error;
94 };
95 
96 namespace internal {
97 
118 template<typename T>
119 struct simdjson_result_base : protected std::pair<T, error_code> {
120 
124  simdjson_inline simdjson_result_base() noexcept;
125 
129  simdjson_inline simdjson_result_base(error_code error) noexcept;
130 
134  simdjson_inline simdjson_result_base(T &&value) noexcept;
135 
139  simdjson_inline simdjson_result_base(T &&value, error_code error) noexcept;
140 
147  simdjson_inline void tie(T &value, error_code &error) && noexcept;
148 
154  simdjson_inline error_code get(T &value) && noexcept;
155 
159  simdjson_inline error_code error() const noexcept;
160 
161 #if SIMDJSON_EXCEPTIONS
162 
168  simdjson_inline T& value() & noexcept(false);
169 
175  simdjson_inline T&& value() && noexcept(false);
176 
182  simdjson_inline T&& take_value() && noexcept(false);
183 
189  simdjson_inline operator T&&() && noexcept(false);
190 #endif // SIMDJSON_EXCEPTIONS
191 
196  simdjson_inline const T& value_unsafe() const& noexcept;
197 
202  simdjson_inline T&& value_unsafe() && noexcept;
203 
204 }; // struct simdjson_result_base
205 
206 } // namespace internal
207 
213 template<typename T>
214 struct simdjson_result : public internal::simdjson_result_base<T> {
218  simdjson_inline simdjson_result() noexcept;
222  simdjson_inline simdjson_result(T &&value) noexcept;
226  simdjson_inline simdjson_result(error_code error_code) noexcept;
230  simdjson_inline simdjson_result(T &&value, error_code error) noexcept;
231 
238  simdjson_inline void tie(T &value, error_code &error) && noexcept;
239 
245  simdjson_warn_unused simdjson_inline error_code get(T &value) && noexcept;
246 
250  simdjson_inline error_code error() const noexcept;
251 
252 #if SIMDJSON_EXCEPTIONS
253 
259  simdjson_inline T& value() & noexcept(false);
260 
266  simdjson_inline T&& value() && noexcept(false);
267 
273  simdjson_inline T&& take_value() && noexcept(false);
274 
280  simdjson_inline operator T&&() && noexcept(false);
281 #endif // SIMDJSON_EXCEPTIONS
282 
287  simdjson_inline const T& value_unsafe() const& noexcept;
288 
293  simdjson_inline T&& value_unsafe() && noexcept;
294 
295 }; // struct simdjson_result
296 
297 #if SIMDJSON_EXCEPTIONS
298 
299 template<typename T>
300 inline std::ostream& operator<<(std::ostream& out, simdjson_result<T> value) { return out << value.value(); }
301 #endif // SIMDJSON_EXCEPTIONS
302 
303 #ifndef SIMDJSON_DISABLE_DEPRECATED_API
307 using ErrorValues [[deprecated("This is an alias and will be removed, use error_code instead")]] = error_code;
308 
312 [[deprecated("Error codes should be stored and returned as `error_code`, use `error_message()` instead.")]]
313 inline const std::string error_message(int error) noexcept;
314 #endif // SIMDJSON_DISABLE_DEPRECATED_API
315 } // namespace simdjson
316 
317 #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:48
@ DEPTH_ERROR
Your document exceeds the user-specified depth limitation.
Definition: error.h:24
@ UNCLOSED_STRING
missing quote at the end
Definition: error.h:34
@ INCORRECT_TYPE
JSON element has a different type than user expected.
Definition: error.h:36
@ 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:45
@ UTF8_ERROR
the input is not valid UTF-8
Definition: error.h:30
@ OUT_OF_BOUNDS
Attempted to access location outside of document.
Definition: error.h:49
@ 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:39
@ UNSUPPORTED_ARCHITECTURE
unsupported architecture
Definition: error.h:35
@ 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:32
@ INVALID_URI_FRAGMENT
Invalid URI fragment.
Definition: error.h:42
@ INDEX_OUT_OF_BOUNDS
JSON array index too large.
Definition: error.h:38
@ NUMBER_OUT_OF_RANGE
JSON number does not fit in 64 bits.
Definition: error.h:37
@ 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:50
@ INCOMPLETE_ARRAY_OR_OBJECT
The document ends early.
Definition: error.h:47
@ UNEXPECTED_ERROR
indicative of a bug in simdjson
Definition: error.h:43
@ UNINITIALIZED
unknown error, or uninitialized document
Definition: error.h:31
@ UNESCAPED_CHARS
found unescaped characters in a string.
Definition: error.h:33
@ IO_ERROR
Error reading a file.
Definition: error.h:40
@ NUMBER_ERROR
Problem while parsing a number.
Definition: error.h:29
@ 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:44
@ INSUFFICIENT_PADDING
The JSON doesn't have enough padding for simdjson to safely parse it.
Definition: error.h:46
@ INVALID_JSON_POINTER
Invalid JSON pointer reference.
Definition: error.h:41
Exception thrown when an exception-supporting simdjson method is called.
Definition: error.h:81
const char * what() const noexcept
The error message.
Definition: error.h:88
error_code error() const noexcept
The error code.
Definition: error.h:90
simdjson_error(error_code error) noexcept
Create an exception from a simdjson error code.
Definition: error.h:86
The result of a simdjson operation that could fail.
Definition: error.h:214
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.