diff --git a/include/nlohmann/detail/diagnostics_t.hpp b/include/nlohmann/detail/diagnostics_t.hpp index a2f7f23a0..c9a1f46d5 100644 --- a/include/nlohmann/detail/diagnostics_t.hpp +++ b/include/nlohmann/detail/diagnostics_t.hpp @@ -58,14 +58,14 @@ class diagnostics_t break; } - default: - break; + default: // LCOV_EXCL_LINE + break; // LCOV_EXCL_LINE } } if (tokens.empty()) { - return ""; + return ""; // LCOV_EXCL_LINE } return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 8d55debbf..d434df940 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -2556,14 +2556,14 @@ class diagnostics_t break; } - default: - break; + default: // LCOV_EXCL_LINE + break; // LCOV_EXCL_LINE } } if (tokens.empty()) { - return ""; + return ""; // LCOV_EXCL_LINE } return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, diff --git a/test/src/unit-diagnostics.cpp b/test/src/unit-diagnostics.cpp index c77030b66..a75f3e972 100644 --- a/test/src/unit-diagnostics.cpp +++ b/test/src/unit-diagnostics.cpp @@ -40,6 +40,13 @@ using nlohmann::json; TEST_CASE("Better diagnostics") { + SECTION("empty JSON Pointer") + { + json j = 1; + std::string s; + CHECK_THROWS_WITH_AS(s = j.get(), "[json.exception.type_error.302] type must be string, but is number", json::type_error); + } + SECTION("invalid type") { json j;