Throw type_error.318 when serializing discarded values to binary formats - #5382
ameliabarnabyhub wants to merge 6 commits into
Conversation
Signed-off-by: ameliabarnabyhub <ameliabarnabyhub@users.noreply.github.com>
Signed-off-by: ameliabarnabyhub <ameliabarnabyhub@users.noreply.github.com>
Signed-off-by: ameliabarnabyhub <ameliabarnabyhub@users.noreply.github.com>
Signed-off-by: ameliabarnabyhub <ameliabarnabyhub@users.noreply.github.com>
Signed-off-by: ameliabarnabyhub <ameliabarnabyhub@users.noreply.github.com>
Signed-off-by: ameliabarnabyhub <ameliabarnabyhub@users.noreply.github.com>
🔴 Amalgamation check failed! 🔴The source code has not been amalgamated and/or formatted correctly. 📎 A ready-to-apply patch is attached to the failed workflow run as the git apply amalgamation.patchThis does not require installing astyle yourself. |
| oa->write_character(to_char_type(0xDB)); | ||
| write_number(static_cast<std::uint32_t>(N)); | ||
| } | ||
| else |
|
|
||
| #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_ | ||
| #define INCLUDE_NLOHMANN_JSON_FWD_HPP_ | ||
| #define INCLUDE_NLOHMANN_JSON_FWD_HPP_ |
There was a problem hiding this comment.
Looks like you have issues with your amalgamate setup.
nlohmann
left a comment
There was a problem hiding this comment.
Thanks for tackling #4714 — the exception-based fix is the right approach. A few issues to resolve before merge, found by Claude Code:
Build-breaking
-
calc_bson_element_sizedoesn't compile under-Werror(include/nlohmann/detail/output/binary_writer.hpp:1264). Thediscarded/defaultcase callsthrow_on_discarded(j)with noreturnafterward, andthrow_on_discardedisn't marked[[noreturn]], so GCC can't prove the non-void function always exits via exception. Confirmed in this PR's own CI:error: control reaches end of non-void function [-Werror=return-type](ci_test_gcc) — this is why essentially every other job in the run is currently red too.- Fix: mark
throw_on_discarded[[noreturn]]/JSON_HEDLEY_NO_RETURN, or add an unreachablereturnafter the call.
- Fix: mark
-
single_include/nlohmann/json.hppandtests/src/unit-msgpack.cppdon't match the pinned amalgamate/astyle output — the diff includes large unrelated reformatting instead of a minimal diff mirroring theinclude/changes. Thecheckjob's own amalgamate+astyle step overwrites these files and then fails (exit 1). Please re-runmake amalgamatewith the pinned toolchain and re-commit.
Other issues
-
out_of_range.412is reused for a second, unrelated condition. It already means "BSON length exceeds int32 max" (documented); this PR repurposes it for "MessagePack size exceeds uint32 max" without updating the docs, which still only describes the BSON case. Please give this its own id or document both meanings. -
No
to_bson()regression test for discarded values —write_bson_element/calc_bson_element_sizenow also throwtype_error.318there, butunit-bson.cppdidn't get the same "discarded" test sections CBOR/MessagePack/UBJSON received. -
The new MessagePack oversized-length branches (
else { assert_msgpack_size(N, &j); }) never write a header before falling through to the payload write — this relies entirely on the throw actually unwinding, otherwise it silently writes an unprefixed payload, the same corruption class this PR fixes for discarded values.
Written by Claude Code on behalf of @niels.
Fixes #4714
Discarded JSON values silently produced broken CBOR, MessagePack, and UBJSON output when nested in arrays or objects (element count/header written but payload skipped). Serialization now throws
type_error.318instead, matching the approach discussed in the issue thread.Adds regression tests for top-level, array, and object cases. Documents the new exception id.