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

Error message path for rule with nested params #685

Open
aleksandra-stolyar opened this issue May 13, 2021 · 1 comment
Open

Error message path for rule with nested params #685

aleksandra-stolyar opened this issue May 13, 2021 · 1 comment

Comments

@aleksandra-stolyar
Copy link

Describe the bug

The error message from dry-validation for incorrect key nesting in en.yml file for rule with nested params is giving wrong path.

To Reproduce

Consider having such schema and some rule depending on several nested parameters.

params do
  required(:data).hash do
    required(:type).filled(:string)
    required(:attributes).hash do
      ....
      required(:phone_number).maybe(:string)
      required(:phone_number_prefix).maybe(:string)
    end
  end
  .....
end

rule(data: {attributes: [:phone_number, :phone_number_prefix]}) do
  phone_number = ....

  key.failure(:invalid) unless phone_number.valid?
end

I tried different nesting of keys in en.yml, but nothing worked. This was the last edit:

en:
  dry_validation:
    errors:
      rules:
        data:
          attributes:
            phone_number:
              phone_number_prefix:
                invalid: 'is of invalid format'

Which as many other tries was giving this error
Dry::Validation::MissingMessageError: Message template for :invalid under "data.attributes.phone_number.phone_number_prefix" was not found for such schema

Expected behavior

Error message with valid path in yml file for such rule or which says that rule name should be written in another way.

Discussion started here:
https://discourse.dry-rb.org/t/message-path-for-rule-with-very-nested-params/1257/3

@moofkit
Copy link
Contributor

moofkit commented Jun 8, 2021

Hi @aleksandra-stolyar! I think you have an issue with configuration.
I was trying to reproduce your bug with this gist

But test is passing for now

$ ruby test.rb
.

Finished in 0.02323 seconds (files took 0.29714 seconds to load)
1 example, 0 failures

You can check this out. Or I miss something?

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

2 participants