dry-configurable icon indicating copy to clipboard operation
dry-configurable copied to clipboard

Unexpected Dry::Schema::MissingMessageError

Open zor-el opened this issue 3 years ago • 0 comments

Describe the bug

Dry validation combined with dry-configurable:0.13.0 raises a Dry::Schema::MissingMessageError exception when the validated attribute is an enum and the actual value isn't one of the listed enums.

This doesn't happen with versions < 0:.13, and although I can't be certain, it stands to reason that the issue is in this gem.

To Reproduce

# frozen_string_literal: true

gem 'dry-configurable', '< 0.13' # passes
# gem 'dry-configurable', '= 0.13.0' # fails

require 'dry-validation'
require 'rspec/autorun'

module Types
  include Dry::Types()
end

class Contract < Dry::Validation::Contract
  params do
    required(:arg).value(Types::Coercible::String.enum('foo', 'bar'))
  end
end

describe 'dry-validation' do
  let(:contract) { Contract.new }
  let(:validation) { contract.(arg: nil) } # or arg: 'xxx'
  subject(:error) { validation.errors.first }

  it 'reports validation errors as messages' do
    expect(error).not_to be_nil
    expect(error.path).to eq [:arg]
    expect(error.text).to eq 'must be one of: foo, bar'
  end
end

relevant error output

 Dry::Schema::MissingMessageError:
       Message template for :arg under "" was not found. Searched in:
       "en.dry_validation.errors.rules.arg.included_in?.arg."
       "en.dry_validation.errors.rules.arg.included_in?"
       "en.dry_validation.errors.included_in?.failure"
       "en.dry_validation.errors.included_in?.value.arg"
       "en.dry_validation.errors.included_in?.value.string.arg."
       "en.dry_validation.errors.included_in?.value.string"
       "en.dry_validation.errors.included_in?.arg."
       "en.dry_validation.errors.included_in?"

Expected behavior

No exception raised. See above.

My environment

Shouldn't be environment-specific, but anyhow:

  • Ruby version: 2.6.5

zor-el avatar Sep 25 '21 07:09 zor-el