Skip to content

Commit 42a7098

Browse files
BridgeARtargos
authored andcommitted
assert: improve error check
Minor performance improvement. PR-URL: #17574 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent dc30ac3 commit 42a7098

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/internal/errors.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,14 @@ class AssertionError extends Error {
219219
red = '\u001b[31m';
220220
}
221221
const util = lazyUtil();
222-
if (actual && actual.stack && actual instanceof Error)
222+
if (typeof actual === 'object' && actual !== null &&
223+
'stack' in actual && actual instanceof Error) {
223224
actual = `${actual.name}: ${actual.message}`;
224-
if (expected && expected.stack && expected instanceof Error)
225+
}
226+
if (typeof expected === 'object' && expected !== null &&
227+
'stack' in expected && expected instanceof Error) {
225228
expected = `${expected.name}: ${expected.message}`;
229+
}
226230

227231
if (errorDiff === 0) {
228232
let res = util.inspect(actual);

0 commit comments

Comments
 (0)