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

MessageMissingError when using predicates as macros and uuid_v3 or uuid_v5

Open mzdemezer opened this issue 2 years ago • 2 comments

Describe the bug

We have run into the same issue as https://github.com/dry-rb/dry-schema/issues/230, but with uuid_v3? and uuid_v5? this time.

To Reproduce

We have run into the bug with code similar to the following one:

require 'dry/schema'

class ExampleService
  include ::Dry::Monads[:do, :result]

  CONTRACT =
    Dry::Schema.Params do
      optional(:filters).hash do
        optional(:id).filled { uuid_v3? | uuid_v4? | uuid_v5? }
        # ...
      end
    end

  private_constant :SCHEMA

  def call(**input)
    valid_data = yield validate(input)
    process(input)
  end

  def validate(input)
    result = CONTRACT.call(input)
    if result.success?
      Success(result.to_h)
    else
      Failure(:invalid_params)
    end
  end

  def process(input)
    # ...
  end
end

upon a call with id in some non-uuid format. The following error message was produced:

API error: Message template for :id under "filters" was not found. Searched in:
"en.dry_schema.errors.rules.id.uuid_v3?.arg.default"
"en.dry_schema.errors.rules.id.uuid_v3?"
"en.dry_schema.errors.uuid_v3?.failure"
"en.dry_schema.errors.uuid_v3?.value.id"
"en.dry_schema.errors.uuid_v3?.value.string.arg.default"
"en.dry_schema.errors.uuid_v3?.value.string"
"en.dry_schema.errors.uuid_v3?.arg.default"
"en.dry_schema.errors.uuid_v3?"

Expected behavior

Proper error message is produced, no exception thrown.

Looking at possible predicates vs the default error messages, how about adding the default messages for v1, v2, v4 and v5?

My environment

  • Affects my production application: YES
  • Ruby version: 3.1.2
  • OS: Linux

mzdemezer avatar Sep 18 '23 13:09 mzdemezer

Thanks for raising this, @mzdemezer. Looks to me like the fix here will be to follow the same approach as https://github.com/dry-rb/dry-schema/pull/244, this time focusing on the other UUID versions and getting proper error messaging support across the board.

Would you like to have a go at it?

timriley avatar Sep 19 '23 02:09 timriley

Hello, I have opened a PR to resolve the issue.

spyroska avatar Mar 12 '24 00:03 spyroska