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

Getting proc instead of string message #736

Open
sekrett opened this issue Jul 10, 2024 · 0 comments
Open

Getting proc instead of string message #736

sekrett opened this issue Jul 10, 2024 · 0 comments

Comments

@sekrett
Copy link

sekrett commented Jul 10, 2024

Describe the bug

I am getting a callable proc in the following code.

To Reproduce

require 'dry-validation'

class TestContract < Dry::Validation::Contract
  params do
    required(:last_name).filled(:string)
    optional(:birthday).maybe(:date)
  end
  
  rule(:birthday) do
    key.failure('wrong date')
  end

  rule(:last_name) do
    result.errors.to_h
  end
end

validator = TestContract.new
puts validator.call(last_name: 'Last', birthday: '5.01.0202').errors.to_h

# {:birthday=>[#<Proc:0x0000000128fc0ed0 /Users/sekrett/.local/share/mise/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/dry-validation-1.10.0/lib/dry/validation/messages/resolver.rb:36 (lambda)>]}

Expected behavior

# {:birthday=>["wrong date"]}

My environment

  • Affects my production application: NO
  • Ruby version: 3.3.0
  • OS: macOS 13.6.7

Workaround

Make a copy of errors:

result.errors.dup.to_h

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

1 participant