Repository navigation
Say why default construction failed when reading a struct with defaults - #11
Closed
clockblocker wants to merge 1 commit into
Closed
clockblocker wants to merge 1 commit into
clockblocker wants to merge 1 commit into
Conversation
A struct that contains rfl::DefaultVal or is read with
rfl::DefaultIfMissing is default-constructed before it is read. If T{}
throws, for instance because a validated field has no valid default
value, the message of the exception was returned as it is:
Size validation failed: Value expected to be greater than or equal
to 1, but got 0.
This reads as if the input was wrong, even when the field is in the
input and valid, and it names neither the struct nor the cause.
What is read and what fails stays the same. But the error now names the
struct, says why it was default-constructed and what to do about it,
followed by the original message:
Could not default-construct Person, which is required because it
contains rfl::DefaultVal. Give every field a valid default value.
Original error: Size validation failed: Value expected to be greater
than or equal to 1, but got 0.
Only a failure of T{} gets this text. An exception thrown later in
read_struct_with_default keeps its own message.
Also document the restriction and the workaround in default_val.md and
processors.md: a field that is given an initializer for this reason
stays required, unless the struct is read with rfl::DefaultIfMissing.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Owner
Author
|
Merged upstream in munich-data-engineering#779. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI-authored
Explains the failure in munich-data-engineering#700 in the error message and in the docs. The read still fails.
For a struct without
rfl::DefaultValthat is read withrfl::DefaultIfMissing, the reason readsbecause it is read with rfl::DefaultIfMissing.What changes
T{}throws inread_struct_with_default, the error names the struct, says why it was default-constructed and what to do, and ends with the original message.docs/content/default_val.mdand a note underrfl::DefaultIfMissingindocs/content/processors.md. They show the workaround:The field stays required (
Field named 'favorite_foods' not found.). Only withrfl::DefaultIfMissingdoes the initializer become the value of a missing field.What does not change
main. Errors from reading the fields keep their text.error().what()with the old text for this case no longer matches.Tests:
tests/json/test_default_construct_error.cpp, 6 tests, 4 of which fail onmain. Run locally, since the fork has no CI: 504 of 504 inctestwith Apple clang 17; json 284 of 284 and generic 99 of 99 with GCC 16.2. Not run: Linux, MSVC, older compilers, the other formats.Related: #10's test expects the bare validator message, so it needs a one-line update when both are merged. #12 builds on this PR and makes the read succeed.
🤖 Generated with Claude Code