-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Check all errors on joi.assert and joi.attempt #1722
Comments
Currently both attempt and assert How would you envision attempt/assert |
@WesTyler I'm not familiar with Lines 170 to 200 in bc09c65
I see that assert and attempt actually use validate . Couldn't we just allow the abortEarly option in both functions? Wouldn't that work right away?
I'm sorry if this is a lame suggestion but I didn't dive deep into the code yet 😄 |
Sorry, I could have been more clear. Validate processes errors into an array of error objects that are added to the result object, while assert/attempt throw the singular error instead. I think that allowing
I'm just trying to get a sense for what your expectation would be as the requester :) |
I think this is wrong. Validate processes errors into an array of error objects, but the result objects get always a single one, the array is being flattened to a single error. So the change would neither require to change the error shape, nor introduce a new error. Lines 756 to 790 in bc09c65
Lines 147 to 210 in bc09c65
That's why I suggested to just allow Am I right or am I missing something? :) |
Oh geez, I'm sorry, you're totally right. I was thinking about something else 😆 |
Haha, no problem 😄 So is this request still valid for you now when you get my point? :) |
Absolutely 👍 |
Awesome! I will pick it up in the next few months if nobody will outrun me 😃 |
Allow validate options to be passed through assert/attempt #1722
Describe the problem you are trying to fix (provide as much context as possible)
I would like
joi.assert
andjoi.attempt
to return all the errors found in the validating object and not throwing just the first one noticed.Which API (or modification of the current API) do you suggest to solve that problem ?
joi.validate
has this exact option viaabortEarly: false
. Unfortunately, I don't like the API of this method as I can't just do a try/catch or anything similar and I always need to doif(valid.error === null)
check and throw the error manually which feels very cumbersome.joi.assert
andjoi.attempt
methods could have the same option to make the API consistent.Are you ready to work on a pull request if your suggestion is accepted ?
Unfortunately, I'm in the middle of a big project and already missing some deadlines and I can't work on it right now 😢 Although I could be available in 2 months to take a look on it.
The text was updated successfully, but these errors were encountered: