Skip to content

Commit 86aa553

Browse files
committed
[Fix] ignore cause in node v16.9 and v16.10 where it has a bug
Note, https://npmjs.com/error-cause fixes this bug
1 parent e243bf2 commit 86aa553

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ module.exports = function inspect_(obj, options, depth, seen) {
187187
}
188188
if (isError(obj)) {
189189
var parts = arrObjKeys(obj, inspect);
190-
if ('cause' in obj && !isEnumerable.call(obj, 'cause')) {
190+
if (!('cause' in Error.prototype) && 'cause' in obj && !isEnumerable.call(obj, 'cause')) {
191191
return '{ [' + String(obj) + '] ' + $join.call($concat.call('[cause]: ' + inspect(obj.cause), parts), ', ') + ' }';
192192
}
193193
if (parts.length === 0) { return '[' + String(obj) + ']'; }

test/err.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ test('type error', function (t) {
4040
'{ [TypeError] foo: 555, bar: [ 1, 2, 3 ] }',
4141
'{ [TypeError: tuv] baz: 555 }',
4242
'{ [SyntaxError: whoa] message: \'whoa\', \'a-b\': 5 }',
43-
'{ [Error: foo] [cause]: \'bar\' }',
44-
'{ [Error: foo] [cause]: \'bar\', foo: \'bar\' }',
45-
'{ [Error: foo] [cause]: undefined }',
43+
'cause' in Error.prototype ? '[Error: foo]' : '{ [Error: foo] [cause]: \'bar\' }',
44+
'{ [Error: foo] ' + ('cause' in Error.prototype ? '' : '[cause]: \'bar\', ') + 'foo: \'bar\' }',
45+
'cause' in Error.prototype ? '[Error: foo]' : '{ [Error: foo] [cause]: undefined }',
4646
'{ [Error: foo] cause: \'bar\' }'
4747
].join(', ') + ' ]');
4848
});

0 commit comments

Comments
 (0)