feat: allow plugins to throw an iterable list of errors

This commit is contained in:
Pierre Vanduynslager
2018-02-11 19:53:41 -05:00
parent 9360caf253
commit 9b2f6bfed2
4 changed files with 43 additions and 6 deletions
+6 -2
View File
@@ -1,4 +1,4 @@
const {identity} = require('lodash');
const {identity, isFunction} = require('lodash');
const pReflect = require('p-reflect');
const pReduce = require('p-reduce');
const AggregateError = require('aggregate-error');
@@ -15,7 +15,11 @@ module.exports = steps => async (input, settleAll = false, getNextInput = identi
if (settleAll) {
const {isFulfilled, value, reason} = await pReflect(nextStep(prevResult));
result = isFulfilled ? value : reason;
(isFulfilled ? results : errors).push(result);
if (isFulfilled) {
results.push(result);
} else {
errors.push(...(result && isFunction(result[Symbol.iterator]) ? result : [result]));
}
} else {
result = await nextStep(prevResult);
results.push(result);