dry-rb / dry-rb/dry-validation

errors(full: true), for nested input, could be better

Open
#731 1 comment 0 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
Ruby
Stars
1.4k
Forks
195
PR merge metrics
No merged PRs in 30d

Description

## Describe the bug

```ruby
result = contract.call(params)

# errors(full: false) works fine ..
result.errors.to_h.to_json
# "{\"items\":{\"0\":{\"weight\":{\"unit\":[\"must be one of: g, kg, lb, oz\"]}}}}"

# errors(full: true), for nested input, could be better
result.errors(full: true).to_h.values.join(', ')
# "{0=\u003e{:weight=\u003e{:unit=\u003e[\"unit must be one of: g, kg, lb, oz\"]}}}"
```

I'm happy to attempt a PR, if requested.

## To Reproduce

Call a Contract that validates nested input, as shown above. If the above is unclear, I'm happy to provide more detail.

## Expected behavior

It'd be great to have better output. For example:

```
result.errors(full: true).to_h.values.join(', ')
# "items 0 weight unit must be one of: g, kg, lb, oz"
```

## My environment

- Affects my production application: No, because I guess I won't be using `errors(full: true)` in production .. :)
- Ruby version: 2.7
- OS: N/A

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the nested Contract case using result.errors(full: true).to_h.values.join(', ') and compare it with errors(full: false). The work is done when nested paths such as items 0 weight unit are rendered in the expected readable form, with coverage for the nested example.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.