jquense / yup

Dead simple Object schema validation
MIT License
22.94k stars 935 forks source link

Validating with an async test does not respect "abortEarly" #2104

Closed romulof closed 1 year ago

romulof commented 1 year ago

Describe the bug

When calling .validate(value, { abortEarly: true }); for a schema with async test, it won't abort early.

To Reproduce

https://codesandbox.io/s/holy-voice-dcwlw2

Expected behavior

asyncTest should not be called if a previous check (.required() and .email() in the example) fail.

Platform (please complete the following information):

Additional context

N/A

jquense commented 1 year ago

abortEarly causes yup to return after the first error it finds, that doesn't mean tests are run sequentially. All tests are run in parallel, using Promise.all depth first through the schema, with abortEarly set it will stop as soon as an error is thrown, but doesn't provide any guarantees which error throws first

romulof commented 11 months ago

If all tests are run with Promise.all how do you abort existing ones when you find an error? Promise.all will execute all and resolve once they are done. The only difference I see is on error reporting, that instead of reporting a list of errors, it would report just the first.

The naming of this property is misleading, because it is not "early".

jquense commented 11 months ago

Promise.all will execute all and resolve once they are done.

That's not quite right. Promise.all resolves as soon as a one of it's promises rejects. I understand your confusion and yes returnEarly or rejectEarly is probably a better name, but it is in fact returning "early".

The only difference I see is on error reporting.

Mostly correct. but it's not just reporting the first one, it's returning control to you as soon as an error returns instead of waiting for every test to finish.