simdjson 5.0.2
Ridiculously Fast JSON
Loading...
Searching...
No Matches
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
9namespace simdjson {
10
56
63 inline bool is_fatal(error_code error) noexcept;
64
82inline const char *error_message(error_code error) noexcept;
83
87inline std::ostream& operator<<(std::ostream& out, error_code error) noexcept;
88
92struct simdjson_error : public std::exception {
97 simdjson_error(error_code error) noexcept : _error{error} { }
99 const char *what() const noexcept override { return error_message(error()); }
101 error_code error() const noexcept { return _error; }
102private:
104 error_code _error;
105};
106
107namespace internal {
108
133template<typename T>
134struct simdjson_result_base : protected std::pair<T, error_code> {
135
139 simdjson_inline simdjson_result_base() noexcept;
140
144 simdjson_inline simdjson_result_base(error_code error) noexcept;
145
149 simdjson_inline simdjson_result_base(T &&value) noexcept;
150
154 simdjson_inline simdjson_result_base(T &&value, error_code error) noexcept;
155
162 simdjson_inline void tie(T &value, error_code &error) && noexcept;
163
169 simdjson_inline error_code get(T &value) && noexcept;
170
174 simdjson_inline error_code error() const noexcept;
175
179 simdjson_inline bool has_value() const noexcept;
180#if SIMDJSON_EXCEPTIONS
181
187 simdjson_inline T& operator*() & noexcept(false);
188 simdjson_inline T&& operator*() && noexcept(false);
194 simdjson_inline T* operator->() noexcept(false);
195 simdjson_inline const T* operator->() const noexcept(false);
196
202 simdjson_inline T& value() & noexcept(false);
203
209 simdjson_inline T&& value() && noexcept(false);
210
216 simdjson_inline T&& take_value() && noexcept(false);
217
223 simdjson_inline operator T&&() && noexcept(false);
224
225#endif // SIMDJSON_EXCEPTIONS
226
245 simdjson_inline const T& value_unsafe() const& noexcept;
246
267 simdjson_inline T&& value_unsafe() && noexcept;
268
269 using value_type = T;
270 using error_type = error_code;
271}; // struct simdjson_result_base
272
273} // namespace internal
274
280template<typename T>
281struct simdjson_result : public internal::simdjson_result_base<T> {
282
286 simdjson_inline simdjson_result() noexcept;
290 simdjson_inline simdjson_result(T &&value) noexcept;
294 simdjson_inline simdjson_result(error_code error_code) noexcept;
298 simdjson_inline simdjson_result(T &&value, error_code error) noexcept;
299
306 simdjson_inline void tie(T &value, error_code &error) && noexcept;
307
313 simdjson_warn_unused simdjson_inline error_code get(T &value) && noexcept;
314
320 template <typename U = T>
321 simdjson_warn_unused simdjson_inline error_code get(std::string &value) && noexcept {
322 static_assert(std::is_same<U, std::string_view>::value, "SFINAE");
323 std::string_view v;
324 error_code error = std::forward<simdjson_result<T>>(*this).get(v);
325 if (!error) {
326 value.assign(v.data(), v.size());
327 }
328 return error;
329 }
330
334 simdjson_inline error_code error() const noexcept;
335
336
337
338#if SIMDJSON_EXCEPTIONS
339 using internal::simdjson_result_base<T>::operator*;
340 using internal::simdjson_result_base<T>::operator->;
346 simdjson_inline T& value() & noexcept(false);
347
353 simdjson_inline T&& value() && noexcept(false);
354
360 simdjson_inline T&& take_value() && noexcept(false);
361
367 simdjson_inline operator T&&() && noexcept(false);
368#endif // SIMDJSON_EXCEPTIONS
369
374 simdjson_inline const T& value_unsafe() const& noexcept;
375
380 simdjson_inline T&& value_unsafe() && noexcept;
381
382 using value_type = T;
383 using error_type = error_code;
384}; // struct simdjson_result
385
386#if SIMDJSON_EXCEPTIONS
387
388template<typename T>
389inline std::ostream& operator<<(std::ostream& out, simdjson_result<T> value) { return out << value.value(); }
390#endif // SIMDJSON_EXCEPTIONS
391
392#ifndef SIMDJSON_DISABLE_DEPRECATED_API
396using ErrorValues [[deprecated("This is an alias and will be removed, use error_code instead")]] = error_code;
397
401[[deprecated("Error codes should be stored and returned as `error_code`, use `error_message()` instead.")]]
402inline const std::string error_message(int error) noexcept;
403#endif // SIMDJSON_DISABLE_DEPRECATED_API
404} // namespace simdjson
405
406#endif // SIMDJSON_ERROR_H
The top level simdjson namespace, containing everything the library provides.
Definition base.h:8
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:25
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_CAPACITY
The capacity was exceeded, we cannot allocate enough memory.
Definition error.h:52
@ OUT_OF_BOUNDS
Attempted to access location outside of document.
Definition error.h:50
@ TAPE_ERROR
Something went wrong, this is a generic error. Fatal/unrecoverable 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
@ UNKNOWN_FIELD
JSON field does not map to any member of the target (see simdjson::deny_unknown_fields)
Definition error.h:53
@ NUM_ERROR_CODES
Placeholder for end of error code list.
Definition error.h:54
@ 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. Fatal/unrecoverable error.
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
bool is_fatal(error_code error) noexcept
Some errors are fatal and invalidate the document.
Definition error-inl.h:10
Exception thrown when an exception-supporting simdjson method is called.
Definition error.h:92
const char * what() const noexcept override
The error message.
Definition error.h:99
error_code error() const noexcept
The error code.
Definition error.h:101
simdjson_error(error_code error) noexcept
Create an exception from a simdjson error code.
Definition error.h:97
The result of a simdjson operation that could fail.
Definition error.h:281
simdjson_warn_unused simdjson_inline error_code get(std::string &value) &&noexcept
Copy the value to a provided std::string, only enabled for std::string_view.
Definition error.h:321