Skip to content

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

Open
@elct9620

Description

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

Activity

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions