@@ -41,7 +41,7 @@ simdjson_really_inline json_iterator::~json_iterator() noexcept {
41
41
#endif
42
42
43
43
SIMDJSON_WARN_UNUSED simdjson_really_inline simdjson_result<bool > json_iterator::start_object () noexcept {
44
- if (*advance () != ' {' ) { logger::log_error (* this , " Not an object" ); return INCORRECT_TYPE ; }
44
+ if (*advance () != ' {' ) { return report_error (INCORRECT_TYPE , " Not an object" ); }
45
45
return started_object ();
46
46
}
47
47
@@ -63,8 +63,7 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline simdjson_result<bool> json_iterator:
63
63
case ' ,' :
64
64
return true ;
65
65
default :
66
- logger::log_error (*this , " Missing comma between object fields" );
67
- return TAPE_ERROR;
66
+ return report_error (TAPE_ERROR, " Missing comma between object fields" );
68
67
}
69
68
}
70
69
@@ -73,7 +72,7 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline simdjson_result<bool> json_iterator:
73
72
do {
74
73
raw_json_string actual_key;
75
74
SIMDJSON_TRY ( get_raw_json_string ().get (actual_key) );
76
- if (*advance () != ' :' ) { logger::log_error (* this , " Missing colon in object field" ); return TAPE_ERROR ; }
75
+ if (*advance () != ' :' ) { return report_error (TAPE_ERROR , " Missing colon in object field" ); }
77
76
if (actual_key == key) {
78
77
logger::log_event (*this , " match" , key);
79
78
return true ;
@@ -89,17 +88,17 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline simdjson_result<bool> json_iterator:
89
88
90
89
SIMDJSON_WARN_UNUSED simdjson_really_inline simdjson_result<raw_json_string> json_iterator::field_key () noexcept {
91
90
const uint8_t *key = advance ();
92
- if (*(key++) != ' "' ) { logger::log_error (* this , " Object key is not a string" ); return TAPE_ERROR ; }
91
+ if (*(key++) != ' "' ) { return report_error (TAPE_ERROR , " Object key is not a string" ); }
93
92
return raw_json_string (key);
94
93
}
95
94
96
95
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::field_value () noexcept {
97
- if (*advance () != ' :' ) { logger::log_error (* this , " Missing colon in object field" ); return TAPE_ERROR ; }
96
+ if (*advance () != ' :' ) { return report_error (TAPE_ERROR , " Missing colon in object field" ); }
98
97
return SUCCESS;
99
98
}
100
99
101
100
SIMDJSON_WARN_UNUSED simdjson_really_inline simdjson_result<bool > json_iterator::start_array () noexcept {
102
- if (*advance () != ' [' ) { logger::log_error (* this , " Not an array" ); return INCORRECT_TYPE ; }
101
+ if (*advance () != ' [' ) { return report_error (INCORRECT_TYPE , " Not an array" ); }
103
102
return started_array ();
104
103
}
105
104
@@ -121,8 +120,7 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline simdjson_result<bool> json_iterator:
121
120
case ' ,' :
122
121
return true ;
123
122
default :
124
- logger::log_error (*this , " Missing comma between array elements" );
125
- return TAPE_ERROR;
123
+ return report_error (TAPE_ERROR, " Missing comma between array elements" );
126
124
}
127
125
}
128
126
@@ -148,7 +146,7 @@ SIMDJSON_WARN_UNUSED simdjson_result<bool> json_iterator::get_bool() noexcept {
148
146
auto not_true = atomparsing::str4ncmp (json, " true" );
149
147
auto not_false = atomparsing::str4ncmp (json, " fals" ) | (json[4 ] ^ ' e' );
150
148
bool error = (not_true && not_false) || jsoncharutils::is_not_structural_or_whitespace (json[not_true ? 5 : 4 ]);
151
- if (error) { logger::log_error (* this , " not a boolean" ); return INCORRECT_TYPE ; }
149
+ if (error) { return report_error (INCORRECT_TYPE , " not a boolean" ); }
152
150
return simdjson_result<bool >(!not_true);
153
151
}
154
152
simdjson_really_inline bool json_iterator::is_null () noexcept {
@@ -181,22 +179,28 @@ constexpr const uint32_t MAX_INT_LENGTH = 1024;
181
179
182
180
SIMDJSON_WARN_UNUSED simdjson_result<uint64_t > json_iterator::get_root_uint64 () noexcept {
183
181
uint8_t tmpbuf[20 +1 ]; // <20 digits> is the longest possible unsigned integer
184
- if (!advance_to_buffer (tmpbuf)) { return NUMBER_ERROR; }
182
+ if (!advance_to_buffer (tmpbuf)) { return report_error ( NUMBER_ERROR, " Root number more than 20 digits " ) ; }
185
183
logger::log_value (*this , " uint64" , " " , 0 );
186
- return numberparsing::parse_unsigned (buf);
184
+ auto result = numberparsing::parse_unsigned (buf);
185
+ if (result.error ()) { report_error (result.error (), " Error parsing unsigned integer" ); }
186
+ return result;
187
187
}
188
188
SIMDJSON_WARN_UNUSED simdjson_result<int64_t > json_iterator::get_root_int64 () noexcept {
189
189
uint8_t tmpbuf[20 +1 ]; // -<19 digits> is the longest possible integer
190
- if (!advance_to_buffer (tmpbuf)) { return NUMBER_ERROR; }
190
+ if (!advance_to_buffer (tmpbuf)) { return report_error ( NUMBER_ERROR, " Root number more than 20 characters " ) ; }
191
191
logger::log_value (*this , " int64" , " " , 0 );
192
- return numberparsing::parse_integer (buf);
192
+ auto result = numberparsing::parse_integer (buf);
193
+ if (result.error ()) { report_error (result.error (), " Error parsing integer" ); }
194
+ return result;
193
195
}
194
196
SIMDJSON_WARN_UNUSED simdjson_result<double > json_iterator::get_root_double () noexcept {
195
197
// Per https://www.exploringbinary.com/maximum-number-of-decimal-digits-in-binary-floating-point-numbers/, 1074 is the maximum number of significant fractional digits. Add 8 more digits for the biggest number: -0.<fraction>e-308.
196
198
uint8_t tmpbuf[1074 +8 +1 ];
197
- if (!advance_to_buffer (tmpbuf)) { return NUMBER_ERROR; }
199
+ if (!advance_to_buffer (tmpbuf)) { return report_error ( NUMBER_ERROR, " Root float more than 1082 digits " ) ; }
198
200
logger::log_value (*this , " double" , " " , 0 );
199
- return numberparsing::parse_double (buf);
201
+ auto result = numberparsing::parse_double (buf);
202
+ if (result.error ()) { report_error (result.error (), " Error parsing double" ); }
203
+ return result;
200
204
}
201
205
SIMDJSON_WARN_UNUSED simdjson_result<bool > json_iterator::get_root_bool () noexcept {
202
206
uint8_t tmpbuf[5 +1 ];
@@ -248,8 +252,7 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::skip_conta
248
252
}
249
253
}
250
254
251
- logger::log_error (*this , " not enough close braces" );
252
- return TAPE_ERROR;
255
+ return report_error (TAPE_ERROR, " not enough close braces" );
253
256
}
254
257
255
258
simdjson_really_inline bool json_iterator::at_start () const noexcept {
@@ -276,6 +279,16 @@ simdjson_really_inline json_iterator_ref json_iterator::borrow() noexcept {
276
279
#endif
277
280
}
278
281
282
+ simdjson_really_inline error_code json_iterator::report_error (error_code error, const char *message) noexcept {
283
+ SIMDJSON_ASSUME (error != SUCCESS && error != UNINITIALIZED && error != INCORRECT_TYPE && error != NO_SUCH_FIELD);
284
+ logger::log_error (*this , message);
285
+ _error = error;
286
+ return error;
287
+ }
288
+ simdjson_really_inline error_code json_iterator::error () const noexcept {
289
+ return _error;
290
+ }
291
+
279
292
//
280
293
// json_iterator_ref
281
294
//
0 commit comments