// We should never reach this point, but it could possibly occur if someone erroneously includes non-ValidationError errors in a validationResult. Note that this is a last-ditch handler, and so we only throw the first non-ValidationError error and let the user sort out the rest, if any.
thrownonValidationErrors[0];
}
}else{
thrownewError(`The 'errors' in a validationResult must be an array`);
}
}elseif(resultinstanceofError){
// We could interpret returned Errors as either values or a throw substitute. Let's wait for users to file issues, so that we know what people *actually* need here.
thrownewError(`It is currently not allowed to return an Error object from a validator. If you have a reason to need this, please file a bug!`);
}else{
return{
errors:[],
newValue:result
};
}
}else{
return{
errors:[],
newValue:undefined
};
}
}catch(error){
if(matchValidationError(error)){
return{
errors:[error],
newValue:undefined
};
}else{
throwerror;
}
}
}
returnfunctioncomposedValidator(value,context){
if(isRequired&&value==null){
returnvalidationResult({
errors:[newValidationError(`Required value is missing`)],
// We should never reach this point, but it could possibly occur if someone erroneously includes non-ValidationError errors in a validationResult. Note that this is a last-ditch handler, and so we only throw the first non-ValidationError error and let the user sort out the rest, if any.
throwresult.errors[0];
}
}else{
thrownewError(`The 'errors' in a validationResult must be an array`);
}
}elseif(resultinstanceofError){
// We could interpret returned Errors as either values or a throw substitute. Let's wait for users to file issues, so that we know what people *actually* need here.
thrownewError(`It is currently not allowed to return an Error object from a validator. If you have a reason to need this, please file a bug!`);
}else{
transformedValue=result;
}
if(transformedValue!=null){
lastValue=transformedValue;
}
if(value!=null||rule.callIfNull===true){
letresult=callRule({
rule:rule,
value:lastValue,
context:context
});
if(result.newValue!=null){
lastValue=result.newValue;
}
}catch(error){
if(matchValidationError(error)){
errors=[error];
}else{
throwerror;
if(result.errors.length>0){
errors=result.errors;
break;
}
}
if(errors.length>0){
break;
}else{
continue;
}
}
@ -82,8 +106,6 @@ module.exports.compose = function composeValidators(validators) {