Skip to content

Error Definitions#27

Merged
feO2x merged 5 commits intomainfrom
26-error-definitions
Mar 19, 2026
Merged

Error Definitions#27
feO2x merged 5 commits intomainfrom
26-error-definitions

Conversation

@feO2x
Copy link
Copy Markdown
Owner

@feO2x feO2x commented Mar 19, 2026

This pull request introduces a new infrastructure for reusable validation error definitions and implements several new built-in assertion methods for the validation library. The main goal is to allow both built-in and custom validation rules to reuse error definitions with clear defaults, ergonomic APIs, and efficient caching, especially for parameterized rules. The changes also provide new assertion methods for common validation scenarios and update documentation to reflect these new capabilities.

Validation Error Definitions Infrastructure:

  • Introduced a new error-definition layer that distinguishes between reusable message templates and immutable validation error definitions, enabling efficient caching and reuse of rule identity and defaults. This includes support for both parameterless and parameterized definitions, a public static catalog for fixed built-ins, and a thread-safe singleton cache for parameterized rules.

New Built-in Assertion Methods:

  • Added new assertion methods to the Light.PortableResults.Validation.Assertions namespace:
    • IsNotNull checks for null values and supports short-circuiting by default.
    • IsGreaterThan and IsLessThan check for comparative boundaries and use the new error-definition infrastructure, with optional short-circuiting. [1] [2]
    • IsIn checks for inclusive range boundaries using cached parameterized definitions.

Documentation and Guidance Updates:

  • Added a comprehensive design plan (ai-plans/0026-error-definitions.md) explaining the rationale, acceptance criteria, technical details, and usage examples for the new validation error definition model and built-in assertions.
  • Updated AGENTS.md to clarify API design guidance and document new validation behaviors, such as how Check<string?> normalizes nulls and how target composition is handled. [1] [2]

These changes make it easier to implement, reuse, and customize validation rules, and they lay the groundwork for more advanced and maintainable validation flows in the library.

@feO2x feO2x self-assigned this Mar 19, 2026
@feO2x feO2x added the enhancement New feature or request label Mar 19, 2026
@feO2x feO2x linked an issue Mar 19, 2026 that may be closed by this pull request
9 tasks
@feO2x feO2x requested a review from Copilot March 19, 2026 05:21
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a reusable “validation error definition” layer (on top of message templates) to enable caching and reuse of rule identity/defaults across validation runs, and adds built-in assertions (IsNotNull, IsGreaterThan, IsLessThan, IsIn) that consume this infrastructure.

Changes:

  • Added ValidationErrorDefinition abstractions plus a thread-safe IValidationErrorDefinitionCache/ValidationErrorDefinitionCache and a built-in catalog (BuiltInValidationErrorDefinitions) for reusable fixed/parameterized definitions.
  • Extended validation context/options/state to expose a shared definition cache and expanded ValidationErrorTemplates with comparable/range templates.
  • Added new built-in Check<T> assertion extensions and comprehensive tests + documentation updates describing the new model.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Light.PortableResults.Validation.Tests/ValidationErrorDefinitionTests.cs Tests for definition defaults, override behavior, cache reuse, and custom definition authoring.
tests/Light.PortableResults.Validation.Tests/BuiltInAssertionTests.cs Tests for new built-in assertions, null handling, short-circuiting, metadata, and target composition.
src/Light.PortableResults.Validation/ValidationState.cs Exposes shared ErrorDefinitionCache via validation state.
src/Light.PortableResults.Validation/ValidationRange.cs Adds immutable range value used for parameterized cache keys.
src/Light.PortableResults.Validation/ValidationErrorTemplates.cs Adds default templates for comparisons and ranges (GreaterThan, LessThan, IsIn).
src/Light.PortableResults.Validation/ValidationErrorMetadataKeys.cs Defines standard metadata keys for boundary/range rules.
src/Light.PortableResults.Validation/ValidationErrorDefinitionCache.cs Implements thread-safe typed-bucket cache for reusable definitions.
src/Light.PortableResults.Validation/ValidationErrorDefinition.cs Introduces base definition abstractions (+ template-backed implementations).
src/Light.PortableResults.Validation/ValidationContextOptions.cs Adds configurable ErrorDefinitionCache with default singleton.
src/Light.PortableResults.Validation/ValidationContext.cs Exposes ErrorDefinitionCache from the active context.
src/Light.PortableResults.Validation/ReadOnlyValidationContext.cs Exposes ErrorDefinitionCache from readonly context view.
src/Light.PortableResults.Validation/IValidationErrorDefinitionCache.cs Adds public cache contract for definition reuse.
src/Light.PortableResults.Validation/IRangeValidationErrorMessageTemplate.cs Adds template contract for range-based messages.
src/Light.PortableResults.Validation/IComparableValidationErrorMessageTemplate.cs Adds template contract for single-boundary comparison messages.
src/Light.PortableResults.Validation/DisplayNameWithRangeValidationErrorMessageTemplate.cs Implements range message formatting with boundary formatting.
src/Light.PortableResults.Validation/DisplayNameWithComparableValidationErrorMessageTemplate.cs Implements comparison message formatting with parameter formatting.
src/Light.PortableResults.Validation/DefaultAutomaticNullErrorProvider.cs Switches automatic null error creation to use the built-in NotNull definition.
src/Light.PortableResults.Validation/Check.cs Adds definition-based AddError overloads and a ShortCircuitOnErrorIfRequested helper; adds category support to message-based AddError.
src/Light.PortableResults.Validation/BuiltInValidationErrorDefinitions.cs Adds built-in reusable definitions and cache-key strategy for parameterized rules.
src/Light.PortableResults.Validation/Assertions/Checks.IsNotNull.cs Adds IsNotNull assertion (default short-circuits).
src/Light.PortableResults.Validation/Assertions/Checks.IsLessThan.cs Adds IsLessThan assertion using cached definitions and templates.
src/Light.PortableResults.Validation/Assertions/Checks.IsIn.cs Adds IsIn assertion using cached range definitions and templates.
src/Light.PortableResults.Validation/Assertions/Checks.IsGreaterThan.cs Adds IsGreaterThan assertion using cached definitions and templates.
ai-plans/0026-error-definitions.md Adds design/acceptance criteria and detailed rationale for the new infrastructure.
AGENTS.md Updates contributor guidance and documents validation semantics (target composition and Check<string?> null normalization).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/Light.PortableResults.Validation/Check.cs
…rmalized when calling Check<T>.AddError

Signed-off-by: Kenny Pflug <[email protected]>
@github-actions
Copy link
Copy Markdown

Code Coverage

Package Line Rate Branch Rate Complexity Health
Light.PortableResults 96% 94% 2300
Light.PortableResults.AspNetCore.MinimalApis 93% 80% 25
Light.PortableResults.AspNetCore.Mvc 93% 80% 26
Light.PortableResults.AspNetCore.Shared 94% 92% 28
Light.PortableResults.Validation 80% 59% 645
Summary 93% (4336 / 4669) 87% (2113 / 2425) 3024

Minimum allowed line rate is 60%

@feO2x feO2x merged commit 96e01d3 into main Mar 19, 2026
2 checks passed
@feO2x feO2x deleted the 26-error-definitions branch March 19, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error Definitions

2 participants