Skip to content

Commit 95c29df

Browse files
committed
refactor(macros): make NLOHMANN_SERIALIZE_ENUM_STRICT use error code 410
- added error code 410 to docs Signed-off-by: Caillin Nugent <caillinn@student.unimelb.edu.au>
1 parent 6d9e0a8 commit 95c29df

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

docs/mkdocs/docs/home/exceptions.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,16 @@ Key identifiers to be serialized to BSON cannot contain code point U+0000, since
868868
BSON key cannot contain code point U+0000 (at byte 2)
869869
```
870870

871+
### json.exception.out_of_range.410
872+
873+
Undefined json fields cannot be used with JSON_SERIALIZE_ENUM_STRICT
874+
875+
!!! failure "Example message"
876+
877+
```
878+
enum value out of range
879+
```
880+
871881
## Further exceptions
872882

873883
This exception is thrown in case of errors that cannot be classified with the

include/nlohmann/detail/macro_scope.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ void templated_json_throw(ExceptionType exception)
286286
return ej_pair.first == e; \
287287
}); \
288288
if (it != std::end(m)) j = it->second; \
289-
else templated_json_throw<nlohmann::detail::out_of_range>(nlohmann::detail::out_of_range::create(403,"enum value out of range",nullptr)); \
289+
else templated_json_throw<nlohmann::detail::out_of_range>(nlohmann::detail::out_of_range::create(410,"enum value out of range",nullptr)); \
290290
} \
291291
template<typename BasicJsonType> \
292292
inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
@@ -301,7 +301,7 @@ void templated_json_throw(ExceptionType exception)
301301
return ej_pair.second == j; \
302302
}); \
303303
if (it != std::end(m)) e = it->first; \
304-
else templated_json_throw<nlohmann::detail::out_of_range>(nlohmann::detail::out_of_range::create(403,"enum value out of range",nullptr)); \
304+
else templated_json_throw<nlohmann::detail::out_of_range>(nlohmann::detail::out_of_range::create(410,"enum value out of range",nullptr)); \
305305
}
306306

307307

tests/src/unit-conversions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,7 @@ TEST_CASE("Strict JSON to enum mapping")
17041704

17051705
// invalid json -> exception thrown
17061706
json _;
1707-
CHECK_THROWS_WITH_AS(_ = json("what?").get<strict_cards>(), "[json.exception.out_of_range.403] enum value out of range", json::out_of_range&);
1707+
CHECK_THROWS_WITH_AS(_ = json("what?").get<strict_cards>(), "[json.exception.out_of_range.410] enum value out of range", json::out_of_range&);
17081708
}
17091709

17101710
SECTION("traditional enum")
@@ -1723,7 +1723,7 @@ TEST_CASE("Strict JSON to enum mapping")
17231723

17241724
// invalid json -> exception thrown
17251725
json _;
1726-
CHECK_THROWS_WITH_AS(_ = json("what?").get<StrictTaskState>(), "[json.exception.out_of_range.403] enum value out of range", json::out_of_range&);
1726+
CHECK_THROWS_WITH_AS(_ = json("what?").get<StrictTaskState>(), "[json.exception.out_of_range.410] enum value out of range", json::out_of_range&);
17271727
}
17281728
}
17291729

0 commit comments

Comments
 (0)