Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors without messages #604

Open
BroiSatse opened this issue Nov 21, 2019 · 2 comments
Open

Errors without messages #604

BroiSatse opened this issue Nov 21, 2019 · 2 comments

Comments

@BroiSatse
Copy link

At the moment validation contract returns nice human-readable errors via translation backend. Being a robot, I do not like it and I'd prefer pure data object/hash to be returned.

Justification: I don't think it is contract responsibility to translate it's errors. When used within API, all the i18n normally happens on the client side, so API can be completely translation-free.

Examples

class MyContract < Dry::Validation::Contract
  json do
    required(:name).filled(:string)
    required(:age).filled(:integer)
  end

  rule(:age) do
    key.failure(:too_young, min: 32) if age < 32
  end
end

contract = MyContract.new
errors = MyContract.new(age: 28).errors

errors.to_h # => {
                   name: [{error: :missing}]
                   age: [{error: :too_young, min: 32}]
                 }

(The above is only example response, I have no strong preference/opinion on how that data should be represented)

Resources

Discourse "discussion": https://discourse.dry-rb.org/t/dry-validation-and-error-translations/919

waiting-for-dev added a commit to waiting-for-dev/dry-schema that referenced this issue Dec 23, 2019
It makes message compiler a specific case of a generic error compiler,
just like new ast error compiler.

References dry-rb/dry-validation#604
waiting-for-dev added a commit to waiting-for-dev/dry-schema that referenced this issue Dec 23, 2019
It makes message compiler a specific case of a generic error compiler,
just like new ast error compiler.

References dry-rb/dry-validation#604
waiting-for-dev added a commit to waiting-for-dev/dry-schema that referenced this issue Dec 23, 2019
It makes message compiler a specific case of a generic error compiler,
just like new ast error compiler.

References dry-rb/dry-validation#604
waiting-for-dev added a commit to waiting-for-dev/dry-schema that referenced this issue Jan 11, 2020
It makes message compiler a specific case of a generic error compiler,
just like new ast error compiler.

References dry-rb/dry-validation#604
@guilherme-andrade
Copy link

Any plans to revisit this issue?

@solnic
Copy link
Member

solnic commented Mar 13, 2022

@guilherme-andrade it's marked as help wanted which means that PRs are welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants