Skip to content

Construct InvalidDataException from validation failures

This constructor is the one exception-hierarchy member with conditional/multi-step logic worth documenting as an operation in its own right: it builds an InvalidDataException whose Message is the semicolon-joined set of the supplied failures' ErrorMessage values, and whose ValidationErrors list holds all supplied failures (BR-CORE-001).

Field Value
Operation ID OP-CORE-002
Trigger A consumer constructs InvalidDataException with a collection of ValidationFailure objects
Inputs IEnumerable<ValidationFailure> failures
Outputs A constructed InvalidDataException with Message and ValidationErrors populated
Primary components SAIF.API.Exceptions.InvalidDataException(IEnumerable<ValidationFailure>)
Entry point src/SAIF.Web.API.Core/SAIFException.cs

Steps

  1. Project failures to their ErrorMessage strings via LINQ .Select(x => x.ErrorMessage). No business rule; no SQL.
  2. Join the projected messages using the ToStringAll(";") extension method (a member of SAIF.Common.Extensions, supplied by a referenced assembly rather than by this project, and presumed to originate from the internal-organization SAIF.Framework.Common NuGet package**) and pass the joined string to the base Exception(string message) constructor (BR-CORE-001).
  3. The join implementation itself was not traced beyond its call site — its defining assembly was not accessible to local source analysis and was not independently retrieved via the Legends CLI RAG service in this pass**.
  4. Materialize failures to a List<ValidationFailure> and assign it to ValidationErrors (BR-CORE-001).

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start(["InvalidDataException<br>constructed with<br>failures"]) --> Project["Project failures to<br>ErrorMessage strings"]
    Project --> Join["Join messages via<br>ToStringAll<br>semicolon-delimited"]
    Join --> Base["Pass joined string to<br>base Exception<br>constructor"]
    Base --> Assign["Materialize failures to<br>list, assign to<br>ValidationErrors"]
    Assign --> Done([Exception constructed])

Failure and edge-case behavior

  • For an empty failures collection, the constructor still projects the (empty) sequence and passes it to ToStringAll(";"); the resulting message is unknown, since the ToStringAll implementation was not traced or independently retrieved**.
  • The ToStringAll join implementation itself was not traced, since SAIF.Common.Extensions is defined outside this repository's scanned source.

Note: Statements marked with ** could not be confirmed; treat as unknown until verified.

Sources

  • src/SAIF.Web.API.Core/SAIFException.cs