Skip to content

Commit

Permalink
assert: improve error check
Browse files Browse the repository at this point in the history
Minor performance improvement.

PR-URL: #17574
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Jon Moss <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
BridgeAR authored and MylesBorins committed Mar 20, 2018
1 parent 9c0c0e6 commit 8d33e5c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,14 @@ class AssertionError extends Error {
red = '\u001b[31m';
}
const util = lazyUtil();
if (actual && actual.stack && actual instanceof Error)
if (typeof actual === 'object' && actual !== null &&
'stack' in actual && actual instanceof Error) {
actual = `${actual.name}: ${actual.message}`;
if (expected && expected.stack && expected instanceof Error)
}
if (typeof expected === 'object' && expected !== null &&
'stack' in expected && expected instanceof Error) {
expected = `${expected.name}: ${expected.message}`;
}

if (errorDiff === 0) {
let res = util.inspect(actual);
Expand Down

0 comments on commit 8d33e5c

Please sign in to comment.