simdjson  3.1.5
Ridiculously Fast JSON
error.h
1 #ifndef SIMDJSON_ERROR_H
2 #define SIMDJSON_ERROR_H
3 
4 #include "simdjson/common_defs.h"
5 #include <string>
6 
7 namespace simdjson {
8 
17 enum error_code {
18  SUCCESS = 0,
49  NUM_ERROR_CODES
50 };
51 
62 inline const char *error_message(error_code error) noexcept;
63 
67 inline std::ostream& operator<<(std::ostream& out, error_code error) noexcept;
68 
72 struct simdjson_error : public std::exception {
77  simdjson_error(error_code error) noexcept : _error{error} { }
79  const char *what() const noexcept { return error_message(error()); }
81  error_code error() const noexcept { return _error; }
82 private:
84  error_code _error;
85 };
86 
87 namespace internal {
88 
109 template<typename T>
110 struct simdjson_result_base : protected std::pair<T, error_code> {
111 
115  simdjson_inline simdjson_result_base() noexcept;
116 
120  simdjson_inline simdjson_result_base(error_code error) noexcept;
121 
125  simdjson_inline simdjson_result_base(T &&value) noexcept;
126 
130  simdjson_inline simdjson_result_base(T &&value, error_code error) noexcept;
131 
138  simdjson_inline void tie(T &value, error_code &error) && noexcept;
139 
145  simdjson_inline error_code get(T &value) && noexcept;
146 
150  simdjson_inline error_code error() const noexcept;
151 
152 #if SIMDJSON_EXCEPTIONS
153 
159  simdjson_inline T& value() & noexcept(false);
160 
166  simdjson_inline T&& value() && noexcept(false);
167 
173  simdjson_inline T&& take_value() && noexcept(false);
174 
180  simdjson_inline operator T&&() && noexcept(false);
181 #endif // SIMDJSON_EXCEPTIONS
182 
187  simdjson_inline const T& value_unsafe() const& noexcept;
188 
193  simdjson_inline T&& value_unsafe() && noexcept;
194 
195 }; // struct simdjson_result_base
196 
197 } // namespace internal
198 
204 template<typename T>
205 struct simdjson_result : public internal::simdjson_result_base<T> {
209  simdjson_inline simdjson_result() noexcept;
213  simdjson_inline simdjson_result(T &&value) noexcept;
217  simdjson_inline simdjson_result(error_code error_code) noexcept;
221  simdjson_inline simdjson_result(T &&value, error_code error) noexcept;
222 
229  simdjson_inline void tie(T &value, error_code &error) && noexcept;
230 
236  simdjson_warn_unused simdjson_inline error_code get(T &value) && noexcept;
237 
241  simdjson_inline error_code error() const noexcept;
242 
243 #if SIMDJSON_EXCEPTIONS
244 
250  simdjson_inline T& value() & noexcept(false);
251 
257  simdjson_inline T&& value() && noexcept(false);
258 
264  simdjson_inline T&& take_value() && noexcept(false);
265 
271  simdjson_inline operator T&&() && noexcept(false);
272 #endif // SIMDJSON_EXCEPTIONS
273 
278  simdjson_inline const T& value_unsafe() const& noexcept;
279 
284  simdjson_inline T&& value_unsafe() && noexcept;
285 
286 }; // struct simdjson_result
287 
288 #if SIMDJSON_EXCEPTIONS
289 
290 template<typename T>
291 inline std::ostream& operator<<(std::ostream& out, simdjson_result<T> value) { return out << value.value(); }
292 #endif // SIMDJSON_EXCEPTIONS
293 
294 #ifndef SIMDJSON_DISABLE_DEPRECATED_API
298 using ErrorValues [[deprecated("This is an alias and will be removed, use error_code instead")]] = error_code;
299 
303 [[deprecated("Error codes should be stored and returned as `error_code`, use `error_message()` instead.")]]
304 inline const std::string error_message(int error) noexcept;
305 #endif // SIMDJSON_DISABLE_DEPRECATED_API
306 } // namespace simdjson
307 
308 #endif // SIMDJSON_ERROR_H
We want to support argument-dependent lookup (ADL).
std::ostream & operator<<(std::ostream &out, error_code error) noexcept
Write the error message to the output stream.
Definition: error-inl.h:36
const char * error_message(error_code error) noexcept
Get the error message for the given error code.
Definition: error-inl.h:21
error_code
All possible errors returned by simdjson.
Definition: error.h:17
@ SCALAR_DOCUMENT_AS_VALUE
A scalar document is treated as a value.
Definition: error.h:46
@ DEPTH_ERROR
Your document exceeds the user-specified depth limitation.
Definition: error.h:22
@ UNCLOSED_STRING
missing quote at the end
Definition: error.h:32
@ INCORRECT_TYPE
JSON element has a different type than user expected.
Definition: error.h:34
@ CAPACITY
This parser can't support a document that big.
Definition: error.h:19
@ OUT_OF_ORDER_ITERATION
tried to iterate an array or object out of order
Definition: error.h:43
@ UTF8_ERROR
the input is not valid UTF-8
Definition: error.h:28
@ OUT_OF_BOUNDS
Attempted to access location outside of document.
Definition: error.h:47
@ TAPE_ERROR
Something went wrong, this is a generic error.
Definition: error.h:21
@ NO_SUCH_FIELD
JSON field not found in object.
Definition: error.h:37
@ UNSUPPORTED_ARCHITECTURE
unsupported architecture
Definition: error.h:33
@ N_ATOM_ERROR
Problem while parsing an atom starting with the letter 'n'.
Definition: error.h:26
@ EMPTY
no structural element found
Definition: error.h:30
@ INVALID_URI_FRAGMENT
Invalid URI fragment.
Definition: error.h:40
@ INDEX_OUT_OF_BOUNDS
JSON array index too large.
Definition: error.h:36
@ NUMBER_OUT_OF_RANGE
JSON number does not fit in 64 bits.
Definition: error.h:35
@ STRING_ERROR
Problem while parsing a string.
Definition: error.h:23
@ MEMALLOC
Error allocating memory, most likely out of memory.
Definition: error.h:20
@ SUCCESS
No error.
Definition: error.h:18
@ T_ATOM_ERROR
Problem while parsing an atom starting with the letter 't'.
Definition: error.h:24
@ TRAILING_CONTENT
Unexpected trailing content in the JSON input.
Definition: error.h:48
@ INCOMPLETE_ARRAY_OR_OBJECT
The document ends early.
Definition: error.h:45
@ UNEXPECTED_ERROR
indicative of a bug in simdjson
Definition: error.h:41
@ UNINITIALIZED
unknown error, or uninitialized document
Definition: error.h:29
@ UNESCAPED_CHARS
found unescaped characters in a string.
Definition: error.h:31
@ IO_ERROR
Error reading a file.
Definition: error.h:38
@ NUMBER_ERROR
Problem while parsing a number.
Definition: error.h:27
@ F_ATOM_ERROR
Problem while parsing an atom starting with the letter 'f'.
Definition: error.h:25
@ PARSER_IN_USE
parser is already in use.
Definition: error.h:42
@ INSUFFICIENT_PADDING
The JSON doesn't have enough padding for simdjson to safely parse it.
Definition: error.h:44
@ INVALID_JSON_POINTER
Invalid JSON pointer reference.
Definition: error.h:39
Exception thrown when an exception-supporting simdjson method is called.
Definition: error.h:72
const char * what() const noexcept
The error message.
Definition: error.h:79
error_code error() const noexcept
The error code.
Definition: error.h:81
simdjson_error(error_code error) noexcept
Create an exception from a simdjson error code.
Definition: error.h:77
The result of a simdjson operation that could fail.
Definition: error.h:205
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.