# Dry-validation and error translations

**URL:** <https://discourse.dry-rb.org/t/dry-validation-and-error-translations/919>\
**Category:** Ideas\
**Created:** [October 7, 2019, 11:49am UTC](https://discourse.dry-rb.org/t/dry-validation-and-error-translations/919 "2019-10-07T11:49:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BroiSatse](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/broisatse/32/435_2.png) [@BroiSatse](https://discourse.dry-rb.org/u/BroiSatse)\
**Post date:** [October 7, 2019, 11:49am UTC](https://discourse.dry-rb.org/t/dry-validation-and-error-translations/919/1 "2019-10-07T11:49:42Z")

</div>

It always strikes me a bit odd that all validation libraries are set on returning validation messages instead of validation errors. This usually mean, that we loose any information about the cause of the error in exchange for translated string.

I believe it strictly view concern to translate messages, which is why I’d like to propose a new messages backend which will not try to generate user friendly messages but return ValidationError instead:

```ruby
class MyContract < Dry::Validation::Contract
  params do
    required(:number).filled(:integer)
  end

  rule :number do
    key.failure(:too_small, minimum: 10) if value && value < 10
  end
end

MyContract.new.({}).errors.to_h #=> { number: [<#Dry::Validation::ValidationError: error: :required>] }

result = MyContract.new.({number: '5'}).errors
result.to_h #=> { number: [<#Dry::Validation::ValidationError: error: :too_small, meta: { minimum: 10 }>] }
result.as_json #=> { number: [{ error: 'too_small', minimum: 10 }]

```

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/solnic/32/779_2.png) [@solnic](https://discourse.dry-rb.org/u/solnic)\
**Post date:** [October 21, 2019, 9:18am UTC](https://discourse.dry-rb.org/t/dry-validation-and-error-translations/919/2 "2019-10-21T09:18:38Z")

</div>

Feel free to report a feature request about it. This could be easily added by adding a configuration setting for message coercion. Currently message set uses `Message#dump` and it’s hardcoded, if this is made configurable then you’ll have what you need.
