I have this verbatim in a simple script:
Promise.all(links.map(function (l) {
return Promise.resolve(require(l).r2gSmokeTest())
.then((v:any) => ({path: l, result: v}));
}))
.then(function(results){
})
.catch(function(e){
}):
the problem is that if the require()
call throws an error for whatever reason, the promise chain won't catch it.
is the simplest thing to do to avoid this to wrap Promise.all in a function, like so:
const getAllPromises = function(links){
return Promise.resolve(null).then(function(){
return Promise.all(links.map(function (l) {
return Promise.resolve(require(l).r2gSmokeTest())
.then((v:any) => ({path: l, result: v}));
}));
it seems to me that maybe Promise.all should have a different API, something like:
Promise.all(function(){
return values.map(v => whatever);
});
that way any errors can be trapped, if Promise.all is not called within a Promise chain...