question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting all errors for a result

See original GitHub issue

Currently a ValidationResult<T> can be used to get errors for a specific field:

result[UserProfile::fullName]

Is there any way to get a map of all errors for a given validation (not a separate list for every field)?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
ghostcommented, Apr 14, 2019

This to me is the single biggest blocker to making this useable in a nice way.

I use various methods of validation, and I encapsulate them in my own interfaces. I think validation is a core part of your logic and should not be embedded in your peripheral http/server frameworks.

For the same reason, I would never expose the data classes or exceptions of an internally used framework in my own API. I will always translate them to my own data types.

Right now, if I wanted to translate the error messages raised by this framework into my own errors, I would have to do some nasty iteration involving reflection on my own classes and their fields.

Please expose the collection of all errors (Map<List<String>, List<String>>).

3reactions
nlochschmidtcommented, May 12, 2018

Not right now.

The main issue is, that I am unsure what the most useful representation would be. One Possibility would be the current internal representation which is Map<List<String>, List<String>>. E.g.

mapOf(
  listOf("user", "fullName") to listOf("is required"),
  listOf("user", "age") to listOf("must be at least 18 years old") 

Another would be a Map<String, Any> where Any might be another Map<String, Any> or a List<String> e.g.

mapOf(
  "user" to mapOf(
    "fullName" to listOf("is required"),
    "age" to listOf("must be at least 18 years old")))

Yet another idea is to have KProperty instead of String as key and also an ValidationError class.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How to return result with the list of errors from function
Show activity on this post. I have faced difficulties trying to return a result combined with the set of errors from function call....
Read more >
Collecting All the Errors - Rust - tarquin-the-brave
Collecting All the Errors - Rust ... A common way to handle iterating over results, Result<T, E> , in Rust is to use...
Read more >
How should I report multiple errors as a result of validation?
For such functions, it is important to report all errors at once, instead of stopping at the very first test at which validation...
Read more >
Error handling: Exception or Result? - Enterprise Craftsmanship
In this post, we'll look at some practical examples of error handling. We will see whether it is better to use exceptions or...
Read more >
Recoverable Errors with Result - The Rust Programming ...
To fix the error, you have two choices. One choice is to change the return type of your function to be compatible with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found