Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Harinath Nampally <[email protected]>
  • Loading branch information
hnampally committed Jan 28, 2025
1 parent 0cda972 commit 3a55919
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ inline void from_json(const BasicJsonType& j, type& e);
Expected output:
```
[json.exception.type_error.302] can't serialize - enum value 3 out of range
[json.exception.type_error.302] serialization failed: enum value 3 is out of range
```
??? example "Example 2: Strict deserialization"
Expand All @@ -73,7 +73,7 @@ inline void from_json(const BasicJsonType& j, type& e);
Expected output:
```
[json.exception.type_error.302] can't deserialize - invalid json value : "yellow"
[json.exception.type_error.302] deserialization failed: invalid json value "yellow"
```
Both examples demonstrate:
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[json.exception.type_error.302] can't serialize - enum value 3 out of range
[json.exception.type_error.302] serialization failed: enum value 3 is out of range
6 changes: 3 additions & 3 deletions include/nlohmann/detail/macro_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ namespace detail
template<typename T>
[[noreturn]] inline void json_throw_from_serialize_macro(T&& exception)
{
#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) || defined(EXCEPTIONS)
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
throw std::forward<T>(exception);
#else
// Forward the exception (even if unused) and abort
Expand Down Expand Up @@ -278,7 +278,7 @@ NLOHMANN_JSON_NAMESPACE_END
}); \
if (it == std::end(m)) { \
auto value = static_cast<typename std::underlying_type<ENUM_TYPE>::type>(e); \
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't serialize - enum value ", std::to_string(value), " out of range"), &j)); \
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("serialization failed: enum value ", std::to_string(value), " is out of range"), &j)); \
} \
j = it->second; \
} \
Expand All @@ -295,7 +295,7 @@ NLOHMANN_JSON_NAMESPACE_END
return ej_pair.second == j; \
}); \
if (it == std::end(m)) \
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't deserialize - invalid json value : ", j.dump()), &j)); \
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("deserialization failed: invalid json value ", j.dump()), &j)); \
e = it->first; \
}

Expand Down
6 changes: 3 additions & 3 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2614,7 +2614,7 @@ namespace detail
template<typename T>
[[noreturn]] inline void json_throw_from_serialize_macro(T&& exception)
{
#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) || defined(EXCEPTIONS)
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
throw std::forward<T>(exception);
#else
// Forward the exception (even if unused) and abort
Expand Down Expand Up @@ -2644,7 +2644,7 @@ NLOHMANN_JSON_NAMESPACE_END
}); \
if (it == std::end(m)) { \
auto value = static_cast<typename std::underlying_type<ENUM_TYPE>::type>(e); \
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't serialize - enum value ", std::to_string(value), " out of range"), &j)); \
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("serialization failed: enum value ", std::to_string(value), " is out of range"), &j)); \
} \
j = it->second; \
} \
Expand All @@ -2661,7 +2661,7 @@ NLOHMANN_JSON_NAMESPACE_END
return ej_pair.second == j; \
}); \
if (it == std::end(m)) \
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't deserialize - invalid json value : ", j.dump()), &j)); \
nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("deserialization failed: invalid json value ", j.dump()), &j)); \
e = it->first; \
}

Expand Down

0 comments on commit 3a55919

Please sign in to comment.