dry-rb/dry-validation

Getting proc instead of string message

Open

#736 建立於 2024年7月10日

在 GitHub 查看
 (2 留言) (0 反應) (0 負責人)Ruby (193 fork)github user discovery
bughelp wanted

倉庫指標

Star
 (1,421 star)
PR 合併指標
 (PR 指標待抓取)

描述

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

貢獻者指南