Repository navigation
Add machine-readable Error::code() and ErrorDetail::code for validator errors - #205
Draft
clockblocker wants to merge 1 commit into
Draft
clockblocker wants to merge 1 commit into
clockblocker wants to merge 1 commit into
Conversation
Owner
Author
For Agents — Provenance, Architecture & Review Metadata
Implementation Invariants & Rebase Notes
Verification Receipt
|
Stacked on discuss/error-kind. Adds machine-readable Error::code() (std::string_view) and ErrorDetail::code (std::string, compared in operator==) for built-in and custom validators. Key changes: - Pack a 1-byte BuiltinErrorCode enum into ErrorKind's tail padding on rfl::Error so built-in validator codes (equal_to, not_equal_to, minimum, exclusive_minimum, maximum, exclusive_maximum, pattern, any_of, one_of, size / size.*, code_points / code_points.*) incur zero heap allocation and zero sizeof(rfl::Error) growth. - Move BuiltinErrorCode string/composition helpers out-of-line into src/rfl/internal/Error.cpp (wired into src/reflectcpp.cpp with RFL_API declarations). - Support custom validator codes per-error via rfl::error(msg, kind[, path], code) or declaratively via a static code member in include/rfl/internal/validator_code.hpp. - Propagate Error::code() through wrap_error and Size/CodePoints/AllOf/Validator wrappers. - Add unit tests in tests/json/test_error_code.cpp and update docs/content/result.md.
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.
Problem
Even with
ErrorKind::constraint_violation, everyrfl::Validatorfailure lands in the same coarse bucket, forcing callers to regex-match EnglishError::what()messages to tell a minimum bound from a pattern or custom rule. API error payloads, localized UI diagnostics, and structured config validators need a stable, machine-readable rule identifier alongsidepathandkind.Proposed API
Adds
Error::code()(std::string_view, empty when unset) andErrorDetail::code(std::string) populated automatically by all built-in validators and optionally by custom validators:sizeof(rfl::Error)growth: Packs a 1-byte tag intoErrorKind's tail padding covering all 27 canonical built-in validator codes.rfl::error(...)or declaratively via astatic codestring member, with per-error codes taking precedence.AllOf,Size,CodePoints), validated map keys, and nested error wrapping while keeping prefix-only wrapping allocation-free for built-in codes.Open Design Questions
static V::codeopt-in vs explicit trait: Any custom validator defining a string-convertiblestaticmember namedcodeautomatically populatesErrorDetail::code. Should that remain convention-based, or require an explicit specialization/tag (orrfl::error(...)calls only) so an unrelatedstatic codeconstant cannot leak into API responses?PatternValidatoraliases: Are the 27 canonical names ("minimum","size.minimum","code_points.maximum","pattern", etc.) the right wire vocabulary, and should aliases likerfl::Emailcontinue emitting"pattern"or expose a distinct rule code?Error::code()or constructing coded errors requires linkingreflectcpp::reflectcpprather than usingreflectcpp::headersalone. Should those lookup tables stay out-of-line or beinlinein the header?Upstream Context
Direct stacked follow-up to #196 (
discuss/error-kind) and merged upstream PRmunich-data-engineering/reflect-cpp#766(Error::details()), completing the structured diagnostic triple(path, kind, code)for validation failures.