using `coerce_with:` lambda without root `Exception` difficult to *debug* unless we help Grape `coerce_value`
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 10k
- Forks
- 1.2k
- Avg merge
- 14h 38m
- Merged PRs (30d)
- 92
Description
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 ?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate Grape::Validations::CoerceValidator#coerce_value and inspect how Types::InvalidValue is initialized. Reproduce the shown coerce_with lambda failure, then verify that the resulting validation error preserves the original exception message without changing successful coercion behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100