diff --git a/lib/internal/errors.js b/lib/internal/errors.js index f83458a6a1d70f..9cc731e99fb3af 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -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);