Skip to content

Add additive ErrorDetail::causes for per-branch std::variant / AnyOf failures #74

Done

Description

@clockblocker

Context

When parsing fails on an untagged std::variant<...> / rfl::Variant<...> or rfl::AnyOf<...> validator, reflect-cpp currently collapses branch failures into a flat message under ErrorKind::invalid_value.

Effect Schema (AnyOf / Composite) and Zod (invalid_union) preserve structured per-branch failure trees so callers and form/RPC UIs can inspect why each alternative failed.

Proposed Additive Design (Post-#70)

Append a defaulted field to rfl::ErrorDetail:

std::vector<ErrorDetail> causes = {};
  • Source-compatible: trailing defaulted aggregate member preserves existing ErrorDetail{path, msg} and designated initializers.
  • Valid C++20: std::vector of an incomplete type is standard since C++17.
  • Zero allocation when empty: +24B per ErrorDetail (only populated on error paths; OptionalDetails remains null on happy path).

Scope & Sequencing

  • Fork-only backlog ticket — intentionally deferred until #70 (rfl::ErrorKind on main) and the follow-up ErrorDetail::code (validator rule ID) PR land upstream so the initial structured-error wave stays minimal and easy for liuzicheng1987 to review.

Activity

  1. added
    enhancement
    needs-triage
    wayfinder:prototype
    and removed
    enhancement
    needs-triage
    on Nov 27, 2026
  2. clockblocker commented on Nov 27, 2026

    @clockblocker
    OwnerAuthor

    Tracked as a Lane 5 Wayfinder prototype ticket under Map (Lane 5): Structured Diagnostics.

    • Showcase Migration evidence: osmium-tool#3 (BBoxObject failing Minimum<-180> inside a union truncated the failing field path and ErrorKind).
    • Throwing Rocks execution: Prototype ErrorDetail::causes on showcase/all-lanes, measure/verify against osmium-tool#3, and run Judges (gemini-4-neon + claude-opus-5-5 high via antigravity delegates) before landing.
  3. added 3 commits that reference this issue on Nov 27, 2026
  4. clockblocker commented on Nov 27, 2026

    @clockblocker
    OwnerAuthor

    Landed on showcase/all-lanes at 2b1fdb9b (62649db6 + 6280453b + 2b1fdb9b), approved by dual independent Judges (claude-opus-5-5 high + gemini-4-neon high, both APPROVE WITH NITS).

    Implemented

    • Appended trailing defaulted std::vector<ErrorDetail> causes = {}; to rfl::ErrorDetail (include/rfl/internal/Error.hpp): source-compatible aggregate/designated initialization, recursive equality + JSON round-trip, zero size growth on sizeof(rfl::Error), and zero allocation on happy paths and leaf errors.
    • Populated 1-cause-per-alternative structured trees (wrapping multi-detail branches in a branch ErrorDetail without flattening) in:
      • include/rfl/parsing/ParserVariant.hpp (lazy std::vector<Error> collection; zero copies/allocations when an alternative matches)
      • include/rfl/parsing/ParserRflVariant.hpp
      • include/rfl/AnyOf.hpp (with custom-validator kind/code normalization)
      • include/rfl/internal/validator_code.hpp (compose_prefixed_validator_error preserves nested causes for Size<AnyOf<...>> and CodePoints<AnyOf<...>>).
    • Verification: tests/json/test_error_causes.cpp (including osmium-tool#3-style BBoxArray | BBoxObject union with single and multi-field failures, nested variants, AnyOf + Size<AnyOf>, and ErrorDetail JSON round-trip) — 1,106/1,106 CTests passing, 0 warnings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wayfinder:prototype

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions