dry-rb/dry-validation

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

Open

#731 geöffnet am 26. Juli 2023

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)Ruby (193 Forks)github user discovery
bughelp wanted

Repository-Metriken

Stars
 (1.421 Stars)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

Describe the bug

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