refactor: return error strings from built-in validators - #1445
Open
henryiii wants to merge 1 commit into
Open
Conversation
Convert the throw sites inside validator lambdas in ExtraValidators.hpp to return the error message through the string-returning contract of Validator::func_. The message that reaches the user is unchanged, since Option::_validate flattened ValidationError to its what() string, which is the raw message. The construction-time checks in AsNumberWithUnit::validate_mapping still throw, since they report programmer errors and are not in the operator() path. Preparation for -fno-exceptions support. Assisted-by: ClaudeCode:claude-fable-5
henryiii
marked this pull request as ready for review
August 21, 2026 03:33
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1445 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 20 20
Lines 5234 5233 -1
Branches 1132 1132
=========================================
- Hits 5234 5233 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
This seems simpler and removes a bunch of throws.
🤖 AI text below 🤖
Part of #1443.
The built-in validators in
ExtraValidators.hpp(IsMember, AsNumberWithUnit/AsSizeValue) threwValidationErrorfrom inside theirfunc_lambdas.Option::_validatecaught these and flattened them to thewhat()string, so the validator contract (return a non-empty string on failure) already covered them. This change makes the lambdas return the same strings directly. User-visible messages are byte-identical, and the catch inOption::_validatestays for user-supplied validators that throw.The construction-time checks in
AsNumberWithUnit::validate_mappingstill throw, since they report programmer errors and have no string-return channel.Preparation for
-fno-exceptionssupport.