SteveDunn / Vogen

A semi-opinionated library which is a source generator and a code analyser. It Source generates Value Objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a Data property to the thrown validation exception.

sirphilliptubell opened this issue · comments

Describe the feature

Many logging frameworks work better when exception messages can be aggregated (meaning they aren't unique). Currently the only way to include the validated value in the exception is to include it in the message. eg: Validation.Invalid($"Invalid ssn: {value}"). Instead the value should be added to the Data property on the exception. This would allow logging frameworks to see the same exception message but still expose the value separately in specific logs. eg:

private static Validation Validate(string? value) {
    return Validation.Invalid("The SSN specified is not valid")
        .WithData("value", value)
        .WithData("notes", "expected 9 digits but found 8");
}

Pull Request #375

Closed via #375