ardalis / ardalis/Result

Add ValidationError constructor that accepts identifier and error message

Open
#208 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
1k
Forks
127
PR merge metrics
No merged PRs in 30d

Description

Aloha!

There appears to be a good amount of overlap between FluentValidation's ValidationFailure and this project's ValidationError class. One slight difference is the ValidationFailure class has a constructor that accepts a property name and error message. Thoughts on adding something similar to the ValidationError class in this repository? I'm not suggesting modifying any of the current constructors, but simply adding one that accepts these two values:

```csharp
public ValidationError(string identifier, string errorMessage)
{
this.Identifier = identifier;
this.ErrorMessage = errorMessage;
}
```

This would simplify the following code:

```csharp
// Current state
new ValidationError(nameof(Model.Name), "Name is required.", "", ValidationSeverity.Error);
// Proposed enhancement
new ValidationError(nameof(Model.Name), "Name is required.")
```

If you approve of the above enhancement I'd be happy to open a PR! Cheers!

Contributor guide

Open the contributing guide

Research direction

Locate the ValidationError class and inspect its existing constructors and properties, especially Identifier and ErrorMessage. Compare the current and proposed construction examples; done means the additional two-argument construction is supported without changing existing constructors and preserves the requested values.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.