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

Struct validation should return ValidationErrors instead of ValidationError #242

Open
wackazong opened this issue Mar 1, 2023 · 8 comments

Comments

@wackazong
Copy link

Thanks for putting this library together. I find it very easy and intuitive.

One question: are there plans to return ValidationErrors from struct validation instead of a single error? I think this would make much more sense since there can be multiple validation problems when validating the whole struct, probably related to specific fields.

@Keats
Copy link
Owner

Keats commented Mar 1, 2023

Thanks!

So usually when doing the struct validation you stop at the first error. At least that is what I always do, no need to do further checks/work if we know it's not good.

@wackazong
Copy link
Author

I think from a user perspective it would be helpful to not get caught in a trial/error loop. Especially if each transaction has an implied cost (I am working on a blockchain project).

From what I can see it should be possible to offer both options?

@Keats
Copy link
Owner

Keats commented Mar 1, 2023

But you have individual field validation which behave the same way and you can hack it with ValidationError::params so I'm not too keen on that right now myself.

Let's see what other people think.

@theduke
Copy link
Contributor

theduke commented May 21, 2023

I agree with @wackazong here.

Concrete examples:

  • validation of API request data:
    An API should report all errors at once, instead of just a single error

  • validation of a configuration file before starting an application.
    As a user, I really want to see all the validation errors at once, instead of having to do a "fix one error, re-run the binary, fix the next error, re-run...

@Keats
Copy link
Owner

Keats commented May 21, 2023

I think that makes sense to change for the next version.

@mseele
Copy link

mseele commented Dec 21, 2023

@Keats do you mind if I do a PR for this feature?

@Keats
Copy link
Owner

Keats commented Dec 22, 2023

Sure but make sure to do it on #249
I'm also wondering in general whether there are better/simpler ways to represent errors than those enums/structs, if you have ideas

@nouman2075
Copy link

Any update on this feature?

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

5 participants