Skip to content

Give a nested error of a whole object the path of the object - #87

Merged
tgharold merged 3 commits into
masterfrom
tgh-20261002-nested-class-level-error-path
Oct 2, 2026
Merged

tgharold merged 3 commits into
masterfrom
tgh-20261002-nested-class-level-error-path

Conversation

@tgharold

@tgharold tgharold commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Motivation

A nested error that belongs to a whole object lost its location. Such an error comes from a class-level attribute or from IValidatableObject.Validate with no member names. Once the object was nested, the result had no member names, so a caller who maps errors to fields or paths could not tell which object failed. A null or empty member name was worse: it gave the path with a dot and nothing after it, such as Value[0]..

The path of the object is the natural member name for these errors, and an error of the root object has no path, so it keeps the names it has. This changes member names that callers might parse, so it is marked BREAKING in the changelog.

This is part 2 of 3 small PRs, in this order: root collection (#86), nested class-level error path (this one), instance properties only. This PR is stacked on #86 and targets its branch, so the diff shows only this change. Merge #86 first. After it merges, GitHub retargets this PR to master.

Summary

  • A nested result with no member names gets the path of the object as its only member name, for example Range or Items[1].
  • A null or empty member name becomes the path alone, so Value[0]. is now Value[0]. Named members are unchanged. An error of the root object keeps its member names.
  • README gets a short "Member names" section. CHANGELOG has a BREAKING entry that lists the old and new names.

Test plan

  • Full suite on net8.0 and net10.0: 586 passed, 7 skipped, 0 failed
  • net481 test project builds with 0 warnings and 0 errors (-p:IncludeNetFramework=true)
  • The new specs fail on the source of Enumerate a collection that is passed as the root object #86 (12 failures on net8.0), and pass with the fix. Commit order: specs, fix, docs.
  • CI on Windows runs the net481 tests

Base automatically changed from tgh-20261002-enumerate-root-collection to master October 2, 2026 20:48
tgharold and others added 3 commits October 2, 2026 16:56
A nested result with no member names, such as one from a class-level
attribute or IValidatableObject, had no member names once nested, so a
caller could not tell which object failed. A null or empty member name
gave the path with a dot and nothing after it. The specs expect the
path of the object as the only member name, such as "Ranges[0]".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A nested result with no member names now gets the path of the object
as its only member name, and a null or empty member name becomes the
path alone. Before, the first had no path and the second ended in a
dot. MVC keys a model-level error by the model's prefix the same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@tgharold
tgharold force-pushed the tgh-20261002-nested-class-level-error-path branch from f7f755e to 7d4e840 Compare October 2, 2026 20:56
@tgharold
tgharold merged commit 664f488 into master Oct 2, 2026
3 checks passed
@tgharold
tgharold deleted the tgh-20261002-nested-class-level-error-path branch October 2, 2026 20:59
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