Repository navigation
YAML error source locations, sequence aggregation, NoDuplicateKeys, alias guards, and SourceMap - #40
Closed
clockblocker wants to merge 5 commits into
Closed
clockblocker wants to merge 5 commits into
clockblocker wants to merge 5 commits into
Conversation
clockblocker
force-pushed
the
yaml-error-locations-and-validation
branch
from
November 25, 2026 10:58
8af794b to
503dcc5
Compare
…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.
Update rfl::yaml::Reader::read_array to continue past failing elements and aggregate all element errors via to_single_error(), matching object field error aggregation while stopping at the first error under rfl::FailFast. Track num_failed_ only on the error path in VectorReader (keeping zero extra instructions on the std::vector happy path for JSON and binary formats), guard std::inplace_vector against emitting duplicate capacity errors on excess elements, and track num_failed_ alongside num_set_ in ArrayReader and TupleReader so indices stay accurate and partial destruction remains safe.
…keys Keep existing default duplicate-key behavior intact for backwards compatibility, and add an opt-in rfl::NoDuplicateKeys processor (matching rfl::NoExtraFields and rfl::EnumNamesOnly). When rfl::NoDuplicateKeys is passed, rfl::yaml::Reader::read_object tracks seen keys per mapping and reports each repeated key as "Duplicate key '<k>'." at the repeated key's source location, aggregated alongside other field errors via add_error() (and honoring rfl::FailFast).
…:load Add an opt-in rfl::SourceMap type mapping ErrorDetail::PathSegment paths to rfl::SourceLocation entries (value and mapping key locations, plus find_nearest fallback to the deepest enclosing ancestor with exact = false). - Move the non-template SourceMap implementation out of the header into src/rfl/SourceMap.cpp (via Pimpl) and keep SourceMap.hpp out of the umbrella rfl.hpp header so non-YAML TUs pay no compile-time cost. - Replace raw node-index mutators with a bounds-safe SourceMap::Builder and opaque SourceMap::NodeId. - Expose RFL_API rfl::yaml::build_source_map(const YAML::Node&) in src/rfl/yaml/Reader.cpp, reusing Reader::ActiveNodeGuard for cycle safety. - Add SourceMap* overloads for rfl::yaml::read and rfl::yaml::load that clear the map up front and populate it on success.
clockblocker
force-pushed
the
yaml-error-locations-and-validation
branch
from
November 25, 2026 11:17
503dcc5 to
264b593
Compare
This was referenced Nov 25, 2026
Owner
Author
|
Split into 5 stacked PRs for easier review:
|
Owner
Author
|
Update: combined #41 and #42 into a single PR (#42, 2 semantic commits off
|
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.
Summary
Improves YAML deserialization diagnostics and safety while remaining backwards-compatible with existing callers and zero-overhead for non-location formats (such as JSON). Structured as 5 independent semantic commits (matching a clean upstream split order):
b1dc17c0— Guardrfl::yaml::Readeragainst recursive aliases and out-of-bounds literal marksYAML::Nodes via a thread-local RAIIActiveNodeGuard(insrc/rfl/yaml/Reader.cpp), rejecting cyclic aliases viarfl::Errorinstead of stack overflow while keepingconst rfl::yaml::Readerthread-safe and allowing non-cyclic (DAG) alias reuse.YAML::Mark::posbefore indexingyaml_str_when trimming literal block scalars.fdea5d61— Add optionalrfl::SourceLocationtorfl::ErrorDetailand populate it in YAMLrfl::ErrorDetailwithstd::optional<rfl::SourceLocation> location = std::nullopt(line,column,exact, 1-based), populated viaif constexpr (requires { _r.source_location(...); })only for readers that support it.attach_source_location()viaError::has_all_source_locations()to avoid O(depth) copies/allocations on nested error unwinding.Error::what()verbatim.af788eb3— Collect all element errors in YAML sequences (honoringrfl::FailFast)rfl::yaml::Reader::read_array(stopping at the first error underrfl::FailFast).num_failed_only on the[[unlikely]]error path inVectorReader(zero extra instructions on thestd::vectorhappy path), guardsstd::inplace_vectoragainst emitting duplicate capacity errors on excess elements, and tracksnum_failed_alongsidenum_set_inArrayReaderandTupleReader.002eeac7— Add opt-inrfl::NoDuplicateKeysprocessor for YAML duplicate mapping keysrfl::NoDuplicateKeysprocessor to reject repeated mapping keys withDuplicate key '<k>'.at the offending key's source location, aggregated alongside other field errors (and honoringrfl::FailFast).264b5939— Add optionalrfl::SourceMapsupport torfl::yaml::readandrfl::yaml::loadrfl::SourceMapmappingErrorDetail::PathSegmentpaths to value/keySourceLocations (plusfind_nearestfallback withexact = false).src/rfl/SourceMap.cpp(via Pimpl) and keepsSourceMap.hppout of umbrellainclude/rfl.hppso non-YAML TUs pay no compile-time cost.SourceMap::Builder+ opaqueSourceMap::NodeIdandRFL_API rfl::yaml::build_source_map(const YAML::Node&)reusingReader::ActiveNodeGuard.Verification
-DREFLECTCPP_JSON=ON -DREFLECTCPP_YAML=ON -DREFLECTCPP_STRICT_WARNINGS=ON): 630/630 passed (generic,json,json_c_arrays_and_inheritance,cli,env,yaml).-DREFLECTCPP_BUILD_SHARED=ONwith-fvisibility=hidden): 85/85 YAML tests passed.-Wall -Werror -fsyntax-only) on all 26 modified/added headers in both C++20 and C++23 (-DREFLECTCPP_USE_STD_EXPECTED), plus C++23 compile checks on all 4 new YAML test files.#include <rfl/...>insideinclude/rfl/.