Skip to content

Commit

Permalink
assert: improve error check
Browse files Browse the repository at this point in the history
Minor performance improvement.
  • Loading branch information
BridgeAR committed Mar 2, 2018
1 parent 452eed9 commit cc1eae9
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 cc1eae9

Please sign in to comment.