Skip to content

Commit

Permalink
assert: support symbols as assertion messages
Browse files Browse the repository at this point in the history
Currently, assertion messages are implicitly converted to strings,
which causes symbols to throw. This commit adds an explicit
string conversion.

PR-URL: #20693
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
cjihrig authored and MylesBorins committed May 22, 2018
1 parent 0d28b4b commit 1160d61
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class AssertionError extends Error {
} = options;

if (message != null) {
super(message);
super(String(message));
} else {
if (process.stdout.isTTY) {
// Reset on each call to make sure we handle dynamically set environment
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,16 @@ common.expectsError(
}
);

common.expectsError(
() => assert(false, Symbol('foo')),
{
code: 'ERR_ASSERTION',
type: assert.AssertionError,
generatedMessage: false,
message: 'Symbol(foo)'
}
);

{
// Test caching.
const fs = process.binding('fs');
Expand Down

0 comments on commit 1160d61

Please sign in to comment.