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

using coerce_with: lambda without root Exception difficult to *debug* unless we help Grape coerce_value #2194

Open
nonnenmacher opened this issue Oct 13, 2021 · 0 comments

Comments

@nonnenmacher
Copy link

in method Grape::Validations::CoerceValidator#coerce_value we loose the root cause of Exception leading to a Types::InvalidValue

Consequence is that the dry-validate errors is somewhat not very helpful

example
I got a params validator that read

coerce_with: ->(val) {
                   (val.nil? || val.empty?) ? nil : Types::PrimaryKey.(val) },

which was obvious to debug after changing

def coerce_value(val)
        converter.call(val)
      # Some custom types might fail, so it should be treated as an invalid value
      rescue StandardError
        Types::InvalidValue.new
      end

to

def coerce_value(val)
        converter.call(val)
      # Some custom types might fail, so it should be treated as an invalid value
      rescue StandardError => e
        Types::InvalidValue.new(e.message)
      end

as indeed Integer#empty? does not exists.

Do you think its reasonable to add this for calling Types::InvalidValue initialiser ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant