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: https://github.com/nodejs/node/issues/11637
PR-URL: https://github.com/nodejs/node/pull/11640
Reviewed-By: Anna Henningsen <anna@addaleax.net>
pull/12727/merge
Cameron Little 2017-03-13 09:07:06 -07:00 committed by Anna Henningsen
parent 74f61e8e1f
commit a3132b0aa5
No known key found for this signature in database
GPG Key ID: D8B9F5AEAE84E4CF
2 changed files with 19 additions and 1 deletions

View File

@ -57,7 +57,7 @@ function setupPromises(scheduleMicrotasks) {
function emitWarning(uid, reason) {
const warning = new Error('Unhandled promise rejection ' +
`(rejection id: ${uid}): ${reason}`);
`(rejection id: ${uid}): ${String(reason)}`);
warning.name = 'UnhandledPromiseRejectionWarning';
warning.id = uid;
if (reason instanceof Error) {

View File

@ -0,0 +1,18 @@
'use strict';
const common = require('../common');
const expectedDeprecationWarning = '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.';
const expectedPromiseWarning = 'Unhandled promise rejection (rejection id: ' +
'1): Symbol()';
common.expectWarning({
DeprecationWarning: expectedDeprecationWarning,
UnhandledPromiseRejectionWarning: expectedPromiseWarning,
});
// ensure this doesn't crash
Promise.reject(Symbol());