Name the exception ids and address review comments

Add detail::exception_id, a scoped enum with one named enumerator per
documented exception id, and use it for every id in the library. The
create() functions get an overload for it; the int overloads stay for
user code.

Following the review of #5783: add binary_reader::invalid_byte() and
length_type_error(), basic_json::throw_subscript_wrong_type(), move the
fuzzer includes and the using-declaration into fuzzer_common.hpp, and
rename test_sax.hpp to sax_event_loggers.hpp.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-10-07 19:38:46 +02:00
1 parent c3068e9f95
commit fce8a8949f
24 files changed
+629 -375

No files matched your search

-4
View File
@@ -51,12 +51,8 @@ The provided function `LLVMFuzzerTestOneInput` can be used in different fuzzer
drivers.
*/
#include <cassert>
#include <nlohmann/json.hpp>
#include "fuzzer_common.hpp"
using nlohmann::json;
// value-stable comparison for the round-trip checks below; see the note
// above on why this compares dump()s rather than the json values directly
static bool is_value_stable(const json& lhs, const json& rhs)
-4
View File
@@ -25,13 +25,9 @@ The provided function `LLVMFuzzerTestOneInput` can be used in different fuzzer
drivers.
*/
#include <cassert>
#include <sstream>
#include <nlohmann/json.hpp>
#include "fuzzer_common.hpp"
using nlohmann::json;
namespace
{
// the serialization of the value read from @a input, or the error message
-4
View File
@@ -21,12 +21,8 @@ The provided function `LLVMFuzzerTestOneInput` can be used in different fuzzer
drivers.
*/
#include <cassert>
#include <nlohmann/json.hpp>
#include "fuzzer_common.hpp"
using nlohmann::json;
// see http://llvm.org/docs/LibFuzzer.html
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
-4
View File
@@ -21,12 +21,8 @@ The provided function `LLVMFuzzerTestOneInput` can be used in different fuzzer
drivers.
*/
#include <cassert>
#include <nlohmann/json.hpp>
#include "fuzzer_common.hpp"
using nlohmann::json;
// see http://llvm.org/docs/LibFuzzer.html
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
-4
View File
@@ -22,12 +22,8 @@ The provided function `LLVMFuzzerTestOneInput` can be used in different fuzzer
drivers.
*/
#include <cassert>
#include <nlohmann/json.hpp>
#include "fuzzer_common.hpp"
using nlohmann::json;
// see http://llvm.org/docs/LibFuzzer.html
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
-4
View File
@@ -21,12 +21,8 @@ The provided function `LLVMFuzzerTestOneInput` can be used in different fuzzer
drivers.
*/
#include <cassert>
#include <nlohmann/json.hpp>
#include "fuzzer_common.hpp"
using nlohmann::json;
// see http://llvm.org/docs/LibFuzzer.html
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
-4
View File
@@ -30,12 +30,8 @@ The provided function `LLVMFuzzerTestOneInput` can be used in different fuzzer
drivers.
*/
#include <cassert>
#include <nlohmann/json.hpp>
#include "fuzzer_common.hpp"
using nlohmann::json;
// see http://llvm.org/docs/LibFuzzer.html
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
+7 -5
View File
@@ -13,6 +13,8 @@
#include <cassert> // assert
#include <nlohmann/json.hpp>
using nlohmann::json; // NOLINT(google-global-names-in-headers): shared by all fuzzer drivers
// the round-trip checks of the drivers are assertions; NDEBUG would compile them away
#ifdef NDEBUG
#error "the fuzzer drivers must be built without NDEBUG"
@@ -20,9 +22,9 @@
// compares dumps rather than values, because NaN != NaN; keep writes strings
// byte for byte, so ill-formed UTF-8 that a binary reader accepts cannot throw
inline bool same_value(const nlohmann::json& lhs, const nlohmann::json& rhs)
inline bool same_value(const json& lhs, const json& rhs)
{
return lhs.dump(-1, ' ', false, nlohmann::json::error_handler_t::keep) == rhs.dump(-1, ' ', false, nlohmann::json::error_handler_t::keep);
return lhs.dump(-1, ' ', false, json::error_handler_t::keep) == rhs.dump(-1, ' ', false, json::error_handler_t::keep);
}
// step 0 of each driver: parse the input without exceptions; a parse error
@@ -30,18 +32,18 @@ inline bool same_value(const nlohmann::json& lhs, const nlohmann::json& rhs)
// out-of-range errors are not parse errors and still throw; then @a threw is
// set and null is returned.
template<typename Parse>
nlohmann::json parse_without_exceptions(Parse parse, bool& threw)
json parse_without_exceptions(Parse parse, bool& threw)
{
threw = false;
try
{
return parse();
}
catch (const nlohmann::json::parse_error&)
catch (const json::parse_error&)
{
assert(false);
}
catch (const nlohmann::json::exception&)
catch (const json::exception&)
{
threw = true;
}
File renamed without changes.
+1 -1
View File
@@ -38,7 +38,7 @@ using nlohmann::json;
#include <vector>
#include "sax_countdown.hpp"
#include "test_sax.hpp"
#include "sax_event_loggers.hpp"
#include "test_utils.hpp"
using utils::SaxCountdown;
+1 -1
View File
@@ -36,7 +36,7 @@ using nlohmann::json;
#include <string>
#include <valarray>
#include "test_sax.hpp"
#include "sax_event_loggers.hpp"
using utils::SaxEventLogger;
using utils::SaxEventLoggerExitAfterKey;