diff --git a/lib/internal/process/promises.js b/lib/internal/process/promises.js index 02c90a928bbc64..e364822fa3a7bf 100644 --- a/lib/internal/process/promises.js +++ b/lib/internal/process/promises.js @@ -45,6 +45,7 @@ function setupPromises(scheduleMicrotasks) { } } + var deprecationWarned = false; function emitPendingUnhandledRejections() { let hadListeners = false; while (pendingUnhandledRejections.length > 0) { @@ -59,6 +60,14 @@ function setupPromises(scheduleMicrotasks) { warning.name = 'UnhandledPromiseRejectionWarning'; warning.id = uid; process.emitWarning(warning); + if (!deprecationWarned) { + deprecationWarned = true; + process.emitWarning( + 'Unhandled promise rejections are deprecated. In the future, ' + + 'promise rejections that are not handled will terminate the ' + + 'Node.js process with a non-zero exit code.', + 'DeprecationWarning'); + } } else { hadListeners = true; } diff --git a/test/parallel/test-promises-warning-on-unhandled-rejection.js b/test/parallel/test-promises-warning-on-unhandled-rejection.js index 9b1e7f3266aba0..b50a5cae416942 100644 --- a/test/parallel/test-promises-warning-on-unhandled-rejection.js +++ b/test/parallel/test-promises-warning-on-unhandled-rejection.js @@ -16,11 +16,14 @@ process.on('warning', common.mustCall((warning) => { assert(/Unhandled promise rejection/.test(warning.message)); break; case 1: + assert.strictEqual(warning.name, 'DeprecationWarning'); + break; + case 2: assert.strictEqual(warning.name, 'PromiseRejectionHandledWarning'); assert(/Promise rejection was handled asynchronously/ .test(warning.message)); } -}, 2)); +}, 3)); const p = Promise.reject('This was rejected'); setImmediate(common.mustCall(() => p.catch(() => {})));