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

Define contract with namespace but got TypeError when use errors(full: true) #734

Open
elct9620 opened this issue Jun 18, 2024 · 0 comments

Comments

@elct9620
Copy link

elct9620 commented Jun 18, 2024

Describe the bug

I have a contract class add config.namespace and try to use .errors(full: true) but got the TypeError

/Users/elct9620/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-schema-1.13.4/lib/dry/schema/messages/namespaced.rb:67:in `sub': wrong argument type Symbol (expected Regexp) (TypeError)

            key.sub(config.top_namespace, "#{config.top_namespace}.#{namespace}")
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To Reproduce

I use it in the dry-rails but get the same result with the below code

# frozen_string_literal: true

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'

  gem 'i18n'
  gem 'dry-validation', '~> 1.10'
end

require 'dry/validation'
require 'i18n'

class ApplicationContract < Dry::Validation::Contract
  config.messages.top_namespace = :contracts
  config.messages.backend = :i18n
end

module Example
  # :nodoc:
  class GroupContract < ApplicationContract
    config.messages.namespace = :example

    params do
      required(:name).filled(:string)
    end
  end
end

contract = Example::GroupContract.new
pp contract.call(name: true).errors(full: true)

Expected behavior

The full error message is displayed correctly.

My environment

  • Affects my production application: Yes
  • Ruby version: 3.3
  • OS: macOS / Ubuntu
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