Skip to content

Commit a3132b0

Browse files
apexskieraddaleax
authored andcommitted
process: cast promise rejection reason to string
The unhandled promise rejection warning uses a template literal and prints the reason a promise was rejected. If rejecting with a symbol, the symbol failed to convert to a string and the process crashed. Now, symbols are casted to strings and the process does not crash. Fixes: #11637 PR-URL: #11640 Reviewed-By: Anna Henningsen <[email protected]>
1 parent 74f61e8 commit a3132b0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/internal/process/promises.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function setupPromises(scheduleMicrotasks) {
5757

5858
function emitWarning(uid, reason) {
5959
const warning = new Error('Unhandled promise rejection ' +
60-
`(rejection id: ${uid}): ${reason}`);
60+
`(rejection id: ${uid}): ${String(reason)}`);
6161
warning.name = 'UnhandledPromiseRejectionWarning';
6262
warning.id = uid;
6363
if (reason instanceof Error) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
const expectedDeprecationWarning = 'Unhandled promise rejections are ' +
5+
'deprecated. In the future, promise ' +
6+
'rejections that are not handled will ' +
7+
'terminate the Node.js process with a ' +
8+
'non-zero exit code.';
9+
const expectedPromiseWarning = 'Unhandled promise rejection (rejection id: ' +
10+
'1): Symbol()';
11+
12+
common.expectWarning({
13+
DeprecationWarning: expectedDeprecationWarning,
14+
UnhandledPromiseRejectionWarning: expectedPromiseWarning,
15+
});
16+
17+
// ensure this doesn't crash
18+
Promise.reject(Symbol());

0 commit comments

Comments
 (0)