From 810af50ba2ab20e006a9e480b911c763f001ce8e Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sat, 12 May 2018 22:15:06 -0400 Subject: [PATCH] assert: support symbols as assertion messages Currently, assertion messages are implicitly converted to strings, which causes symbols to throw. This commit adds an explicit string conversion. PR-URL: https://github.com/nodejs/node/pull/20693 Reviewed-By: Daniel Bevenius Reviewed-By: Luigi Pinca Reviewed-By: Ruben Bridgewater Reviewed-By: Trivikram Kamat Reviewed-By: James M Snell --- lib/internal/assert.js | 2 +- test/parallel/test-assert.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/internal/assert.js b/lib/internal/assert.js index 990065a9378f14..74f7e3f7c053c4 100644 --- a/lib/internal/assert.js +++ b/lib/internal/assert.js @@ -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 diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index bf9d6c6eb48ce0..51c9e677b1e221 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -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');