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

MessageMissingError when using predicates as macros and uuid_v3 or uuid_v5 #470

Open
mzdemezer opened this issue Sep 18, 2023 · 2 comments

Comments

@mzdemezer
Copy link

Describe the bug

We have run into the same issue as #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
@timriley
Copy link
Member

Thanks for raising this, @mzdemezer. Looks to me like the fix here will be to follow the same approach as #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?

@spyroska
Copy link

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

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

3 participants