Skip to content

YAML recursive alias guard and rfl::SourceLocation on ErrorDetail - #42

Closed
clockblocker wants to merge 2 commits into
wave-base-12from
yaml-error-source-locations
Closed

clockblocker wants to merge 2 commits into
wave-base-12from
yaml-error-source-locations

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Part 1 of 4 (split from #40). Contains 2 semantic commits:

  1. b1dc17c0 — Guard rfl::yaml::Reader against recursive aliases and out-of-bounds literal marks

    • Adds an out-of-line thread-local RAII guard (Reader::ActiveNodeGuard in src/rfl/yaml/Reader.cpp) used by read_object and read_array so cyclic YAML aliases return an rfl::Error instead of overflowing the stack, while keeping const rfl::yaml::Reader thread-safe and allowing non-cyclic (DAG) alias reuse.
    • Bounds-checks YAML::Mark::pos before indexing yaml_str_ when trimming trailing newlines on literal block scalars.
    • Adds focused tests in tests/yaml/test_recursive_alias.cpp.
  2. a7e7ccde — Add optional rfl::SourceLocation to rfl::ErrorDetail and populate it in YAML

    • Extends rfl::ErrorDetail with std::optional<rfl::SourceLocation> location = std::nullopt (line, column, exact, 1-based), re-exported from include/rfl/Result.hpp.
    • Populates locations only for readers providing source_location(...) via if constexpr (requires { ... }), leaving non-location formats (JSON, binary, etc.) untouched with zero hot-path overhead.
    • Short-circuits attach_source_location() via Error::has_all_source_locations() to avoid O(depth) copies/allocations during deep error unwinding.
    • Preserves Error::what() verbatim and documents both SourceLocation and recursive alias rejection in docs/content/result.md and docs/content/supported_formats/yaml.md.
    • Adds tests in tests/yaml/test_error_details.cpp.

Verification

  • Verified full shared-library CMake suite (-DREFLECTCPP_BUILD_SHARED=ON -DREFLECTCPP_JSON=ON -DREFLECTCPP_YAML=ON -DREFLECTCPP_STRICT_WARNINGS=ON with -fvisibility=hidden): 631/631 passed, plus C++20/C++23 (-DREFLECTCPP_USE_STD_EXPECTED) self-contained header checks.

@clockblocker clockblocker changed the title Add optional rfl::SourceLocation to rfl::ErrorDetail and populate it in YAML YAML recursive alias guard and rfl::SourceLocation on ErrorDetail Nov 25, 2026
@clockblocker
clockblocker changed the base branch from yaml-recursive-alias-guard to main November 25, 2026 11:28
@clockblocker
clockblocker force-pushed the yaml-error-source-locations branch from fdea5d6 to a7e7ccd Compare November 25, 2026 11:39
@clockblocker
clockblocker force-pushed the yaml-error-source-locations branch from a7e7ccd to 3e01422 Compare November 25, 2026 12:06
@clockblocker
clockblocker changed the base branch from main to wave-base-12 November 25, 2026 12:06
@clockblocker
clockblocker force-pushed the yaml-error-source-locations branch from 3e01422 to 5013acd Compare November 25, 2026 12:08
…iteral marks

Track ancestor YAML nodes via a thread-local RAII guard (ActiveNodeGuard in
src/rfl/yaml/Reader.cpp) across read_object and read_array so cyclic YAML
aliases return an rfl::Error instead of overflowing the stack, while keeping
const Reader instances thread-safe and allowing non-cyclic (DAG) alias reuse.

Also bounds-check YAML::Mark::pos before indexing yaml_str_ when trimming
trailing newlines on literal block scalars.
…in YAML

Extend rfl::ErrorDetail with an optional rfl::SourceLocation{line, column, exact}
(1-based), filled in by readers that provide source_location(...) and left
std::nullopt by other readers with zero hot-path overhead.

attach_source_location() short-circuits via Error::has_all_source_locations()
so unwinding deeply nested errors does not allocate or copy once leaf locations
are populated. Wrapping preserves leaf locations and Error::what() stays
unchanged.
@clockblocker

Copy link
Copy Markdown
Owner Author

Branch is preserved on fork and showcase/all-lanes (d0f1fca1) as a reference artifact and parked in #117 (Moonshots & Possible Scope Creep).

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