NodeJS version 8.11 - The warning is "This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch()."
Neither of these are true, which you can see by inspecting my test case:
const DEMONSTRATE_FAILURE = false
async function doPromises() {
try {
if (DEMONSTRATE_FAILURE) {
// This causes UnhandledPromiseRejectionWarning warnings:
const brokenPromises = [createPromises(), createPromises()]
await brokenPromises[0]
await brokenPromises[1]
} else {
// This works fine:
await createPromises()
await createPromises()
}
} catch(err) {
process.stdout.write("x")
}
}
// Create 10 promises, of which 50% will reject after between 0 and 1000ms
function createPromises() {
let badPromises = []
for (let x = 0; x < 10; x++) {
badPromises.push(new Promise((resolve, reject) => {
setTimeout(() => {
if (Math.random() > 0.5) {
process.stdout.write("-")
reject("rejected!")
} else {
process.stdout.write("+")
resolve()
}
}, Math.round(Math.random() * 1000))
}))
}
return Promise.all(badPromises)
}
(async function main() {
while (true) {
await doPromises()
}
})()
Flip the DEMONSTRATE_FAILURE
flag to see the same code running with and without the error.