// NOTE: We only unpack `either` errors that occurred *at the same level* as this error, ie. where there's directly a case of `either(either(...), ...)`, without any kind of data nesting (like `arrayOf` or `hasShape`) inbetween. Nested-data failures should still be shown separately, as their resolution strategy is actually different; unlike same-level nested `either` errors, where the nesting is purely an implementation detail that allows composing sets of alternatives together.
thrownewError(`Must specify an array of alternatives`);
@ -27,8 +40,12 @@ module.exports = function (alternatives) {
if(errors.length===0){
returnnewValue;
}elseif(errors.length===1){
allErrors.push(errors[0]);
}else{
allErrors.push(...errors);
allErrors.push(newValidationError("Must satisfy all of the following:",{
subErrors:errors
}));
}
}
@ -54,7 +71,10 @@ module.exports = function (alternatives) {
// One of the alternatives *did* match, but it failed somewhere further down the tree, and we don't have any errors originating from *other* nested rules. Chances are that the user intended to match the failing branch, so we pretend that the other alternatives don't exist, and pass through the original error(s).
returnvalidationResult({errors:nestedErrors});
}else{
thrownewValidationError(`Must satisfy at least one of:`,{subErrors:allErrors});
thrownewValidationError(`Must satisfy at least one of:`,{