Description
Version: v11.1.0
Platform: Linux myhost 4.18.0-10-generic #11-Ubuntu SMP Thu Oct 11 15:13:55 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
When using Promise.all()
or Promise.race()
, several child promises might be legitimately rejected. This might be intended by the developer, so it should not trigger a multipleResolves
process error. This is in contrast to calling reject()
several times in new Promise()
which definitely indicates a programming error.
'use strict'
process.on('multipleResolves', function() {
console.log('This should not be called')
})
Promise.all([Promise.reject(), Promise.reject()])
Use case 1: a unit test is checking that an async function returns a rejected promise. The unit test fires the function several times in parallel for performance reason. The test expects each function call to reject a promise. I.e. multipleResolves
should not be fired.
Use case 2: I created a library log-process-errors which logs every process errors (including multipleResolves
). The goal is to make sure process errors are properly logged in production, so they can be fixed. However this does not work if Node.js is triggering them where there is no programming errors.