Keats / validator

Simple validation for Rust structs
MIT License
2.03k stars 147 forks source link

Struct validation should return ValidationErrors instead of ValidationError #242

Open wackazong opened 1 year ago

wackazong commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

I agree with @wackazong here.

Concrete examples:

Keats commented 1 year ago

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

mseele commented 10 months ago

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

Keats commented 10 months ago

Sure but make sure to do it on https://github.com/Keats/validator/pull/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 commented 5 months ago

Any update on this feature?