Skip to content

refactor: return error strings from built-in validators - #1445

Open
henryiii wants to merge 1 commit into
mainfrom
refactor/validators-return-strings
Open

refactor: return error strings from built-in validators#1445
henryiii wants to merge 1 commit into
mainfrom
refactor/validators-return-strings

Conversation

@henryiii

@henryiii henryiii commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

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) threw ValidationError from inside their func_ lambdas. Option::_validate caught these and flattened them to the what() 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 in Option::_validate stays for user-supplied validators that throw.

The construction-time checks in AsNumberWithUnit::validate_mapping still throw, since they report programmer errors and have no string-return channel.

Preparation for -fno-exceptions support.

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
henryiii marked this pull request as ready for review August 21, 2026 03:33
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (75933a4) to head (474f6af).
⚠️ Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant