You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unhandled promise rejection with a symbol crashes node #11637
Platform: Darwin Chelan.local 16.3.0 Darwin Kernel Version 16.3.0: Thu Nov 17 20:23:58 PST 2016; root:xnu-3789.31.2~1/RELEASE_X86_64 x86_64
Subsystem: internal/process/promises.js
Rejecting a promise with a Symbol will crash node. I'd expect it to handle this, or at least to crash in a different way. The traceback indicates node is unable to convert a Symbol to a string, though this is possible both in the REPL and when using .toString().
A simple demo session:
$ node
> const s = Symbol()
undefined
> s
Symbol()
> s.toString()
'Symbol()'
> const s2 = Symbol("label")
undefined
> s2
Symbol(label)
> s2.toString()
'Symbol(label)'
> Promise.reject(s2)
Promise { <rejected> Symbol(label) }
> internal/process/promises.js:60
`(rejection id: ${uid}): ${reason}`);
^
TypeError: Cannot convert a Symbol value to a string
at emitWarning (internal/process/promises.js:60:58)
at emitPendingUnhandledRejections (internal/process/promises.js:86:11)
at runMicrotasksCallback (internal/process/next_tick.js:61:9)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
1 ↩
The correct code would be to use ${String(reason)}, since on a spec level the String function has special handling for symbols in addition to the ToString abstract operation which template strings use, which throws on symbols.
What I'm more worried about is that we might have to conduct a comprehensive audit for template string usage in the code base for possibility of symbols, since it's possible that they are going to blow up as well.
node: v8.1.4
environment: windows 10 x64
Having same issue:
`(rejection id: ${uid}): ${String(reason)}`);
TypeError: Function.prototype.toString is not generic
at InvalidValueError.toString (<anonymous>)
at String (<anonymous>)
at emitWarning (internal/process/promises.js:60:58)
at emitPendingUnhandledRejections (internal/process/promises.js:86:11)
at runMicrotasksCallback (internal/process/next_tick.js:89:9)
at _combinedTickCallback (internal/process/next_tick.js:95:7)
at process._tickCallback (internal/process/next_tick.js:161:9)
Activity
TimothyGu commentedon Mar 1, 2017
The correct code would be to use
${String(reason)}, since on a spec level theStringfunction has special handling for symbols in addition to theToStringabstract operation which template strings use, which throws on symbols.What I'm more worried about is that we might have to conduct a comprehensive audit for template string usage in the code base for possibility of symbols, since it's possible that they are going to blow up as well.
apexskier commentedon Mar 1, 2017
Cool. I was thinking
reason.toString(), but I'll try that. I've got a PR incoming that adds a test case and fixes the issue.TimothyGu commentedon Mar 1, 2017
@apexskier, that wouldn't work in cases like
Object.create(null)which doesn't have atoString().muhammadfaizan commentedon Sep 29, 2017
node: v8.1.4
environment: windows 10 x64
Having same issue:
ljharb commentedon Sep 29, 2017
What does InvalidValueError look like?
TimothyGu commentedon Sep 29, 2017
@muhammadfaizan Try Node.js 8.5.0. It should be fixed in #13784.
process: cast promise rejection reason to string