> For the complete documentation index, see [llms.txt](https://draekien-industries.wpei.me/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://draekien-industries.wpei.me/waystone.monads.fluentvalidation/using-the-library/validationerr.md).

# ValidationErr

This library wraps the `ValidationResult` provided by [FluentValidation](https://docs.fluentvalidation.net/en/latest/index.html) inside the `ValidationErr` class. `ValidationErr` is designed to capture and expose validation failures in a way that integrates smoothly with the functional patterns provided by [Waystone.Monads](https://draekien-industries.wpei.me/).

{% hint style="info" %}
`ValidationErr` isolates the failure case of the `ValidationResult`
{% endhint %}

## Creation

A `ValidationErr` can be created by invoking the `Create` factory method and providing it with a `ValidationResult`. The factory will return an [Option\<T>](/using-the-library/option-of-t.md) of `ValidationErr` which will be `Some` if the provided `ValidationResult` is invalid.

```csharp
class GreaterThanZeroValidator : AbstractValidator<int>
{
    public GreaterThanZeroValidator()
    {
         RuleFor(x => x).GreaterThanZero();   
    }
}

int x = -1;
GreaterThanZeroValidator validator = new();
ValidationResult result = validator.Validate(x);
Option<ValidationErr> maybeValidationErr = ValidationErr.Create(result);
//                    ^? Some(ValidationErr)
```

{% hint style="info" %}
In most cases, you will want to use the [Validating Values](/waystone.monads.fluentvalidation/using-the-library/validating-values.md#validate) or [Validating Values](/waystone.monads.fluentvalidation/using-the-library/validating-values.md#validateasync) extension methods instead.
{% endhint %}

## Properties

`ValidationErr` provides access to the underlying validation result's failure properties:

* `Errors`: the list of validation failures as exposed by the `ValidationResult`
* `RuleSetsExecuted`: the array of rulesets executed as exposed by the `ValidationResult`

## Methods

`ValidationErr` provides the following helper methods:

* `ToError()`: converts the validation failures into an `Error`, using the code and fallback message you set in [Configuration](/waystone.monads.fluentvalidation/using-the-library/configuration.md)
* `ToDictionary()`: converts the `ValidationResult` into a dictionary
* `ToString()`: converts the `ValidationResult` into a string
* `AsValidationResult()`: provides access to the underlying `ValidationResult`
