Skip to content

Commit

Permalink
[Fix] ignore cause in node v16.9 and v16.10 where it has a bug
Browse files Browse the repository at this point in the history
Note, https://npmjs.com/error-cause fixes this bug
  • Loading branch information
ljharb committed May 26, 2022
1 parent e243bf2 commit 86aa553
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ module.exports = function inspect_(obj, options, depth, seen) {
}
if (isError(obj)) {
var parts = arrObjKeys(obj, inspect);
if ('cause' in obj && !isEnumerable.call(obj, 'cause')) {
if (!('cause' in Error.prototype) && 'cause' in obj && !isEnumerable.call(obj, 'cause')) {
return '{ [' + String(obj) + '] ' + $join.call($concat.call('[cause]: ' + inspect(obj.cause), parts), ', ') + ' }';
}
if (parts.length === 0) { return '[' + String(obj) + ']'; }
Expand Down
6 changes: 3 additions & 3 deletions test/err.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ test('type error', function (t) {
'{ [TypeError] foo: 555, bar: [ 1, 2, 3 ] }',
'{ [TypeError: tuv] baz: 555 }',
'{ [SyntaxError: whoa] message: \'whoa\', \'a-b\': 5 }',
'{ [Error: foo] [cause]: \'bar\' }',
'{ [Error: foo] [cause]: \'bar\', foo: \'bar\' }',
'{ [Error: foo] [cause]: undefined }',
'cause' in Error.prototype ? '[Error: foo]' : '{ [Error: foo] [cause]: \'bar\' }',
'{ [Error: foo] ' + ('cause' in Error.prototype ? '' : '[cause]: \'bar\', ') + 'foo: \'bar\' }',
'cause' in Error.prototype ? '[Error: foo]' : '{ [Error: foo] [cause]: undefined }',
'{ [Error: foo] cause: \'bar\' }'
].join(', ') + ' ]');
});

0 comments on commit 86aa553

Please sign in to comment.