-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <anna@addaleax.net>
- Loading branch information
Showing
2 changed files
with
19 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
test/parallel/test-promises-unhandled-symbol-rejections.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); |