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: nodejs#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 committed Mar 6, 2018
1 parent 4e15679 commit b5825e1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,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 b5825e1

Please sign in to comment.