mirror of
https://github.com/nlohmann/json.git
synced 2026-10-09 16:07:14 +00:00
Factor out more repeated error paths and test boilerplate
Library: - add throw_cannot_use_with() for the 34 copies of type_error.304-312 "cannot use X with Y" - iter_impl: add throw_cannot_get_value() (invalid_iterator.214) - parser: add syntax_error() for the 12 parse_error.101 sites - ordered_map: share the four at() bodies via at_impl() - json_sax_dom_callback_parser: add pop_container() for end_object() and end_array() - binary_reader: build the two UBJSON/BJData length-type messages with concat() and last_byte_error() Tests: - move same_value(), the NDEBUG guard, and step 0 (parse without exceptions) of the seven fuzzer drivers into tests/src/fuzzer_common.hpp Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
16 files changed
+337
-481
No files matched your search
@@ -2566,18 +2566,10 @@ class binary_reader
|
||||
default:
|
||||
break;
|
||||
}
|
||||
auto last_token = get_token_string();
|
||||
std::string message;
|
||||
|
||||
if (input_format != input_format_t::bjdata)
|
||||
{
|
||||
message = "expected length type specification (U, i, I, l, L); last byte: 0x" + last_token;
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "expected length type specification (U, i, u, I, m, l, M, L); last byte: 0x" + last_token;
|
||||
}
|
||||
return last_byte_error(113, message, "string");
|
||||
const char* expected = input_format != input_format_t::bjdata
|
||||
? "expected length type specification (U, i, I, l, L)"
|
||||
: "expected length type specification (U, i, u, I, m, l, M, L)";
|
||||
return last_byte_error(113, concat(expected, "; last byte: 0x", get_token_string()), "string");
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -2840,18 +2832,10 @@ class binary_reader
|
||||
default:
|
||||
break;
|
||||
}
|
||||
auto last_token = get_token_string();
|
||||
std::string message;
|
||||
|
||||
if (input_format != input_format_t::bjdata)
|
||||
{
|
||||
message = "expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token;
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x" + last_token;
|
||||
}
|
||||
return last_byte_error(113, message, "size");
|
||||
const char* expected = input_format != input_format_t::bjdata
|
||||
? "expected length type specification (U, i, I, l, L) after '#'"
|
||||
: "expected length type specification (U, i, u, I, m, l, M, L) after '#'";
|
||||
return last_byte_error(113, concat(expected, "; last byte: 0x", get_token_string()), "size");
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
Reference in new issue
Block a user