Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/internal/assert/assertion_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ObjectDefineProperty,
ObjectGetPrototypeOf,
ObjectPrototypeHasOwnProperty,
SafeSet,

Check failure on line 13 in lib/internal/assert/assertion_error.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'SafeSet' is assigned a value but never used
String,
StringPrototypeRepeat,
StringPrototypeSlice,
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1955,15 +1955,15 @@ function formatError(err, constructor, tag, ctx, keys) {
}
name ??= 'Error';

if ('cause' in err &&
if (ObjectPrototypeHasOwnProperty(err, 'cause') &&
(keys.length === 0 || !ArrayPrototypeIncludes(keys, 'cause'))) {
ArrayPrototypePush(keys, 'cause');
}

// Print errors aggregated into AggregateError
try {
const errors = err.errors;
if (ArrayIsArray(errors) &&
if (ArrayIsArray(errors) && ObjectPrototypeHasOwnProperty(err, 'errors') &&
(keys.length === 0 || !ArrayPrototypeIncludes(keys, 'errors'))) {
ArrayPrototypePush(keys, 'errors');
}
Expand Down
47 changes: 47 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,53 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
);
}

{
// No own errors or cause property.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;

const e1 = new Error('e1');
const e2 = new TypeError('e2');
const e3 = false;

const errors = [e1, e2, e3];
const aggregateError = new AggregateError(errors, 'Foobar');

assert.deepStrictEqual(aggregateError.errors, errors);
assert.strictEqual(
util.inspect(aggregateError),
'[AggregateError: Foobar] {\n [errors]: [ [Error: e1], [TypeError: e2], false ]\n}'
);


const custom = new Error('No own errors property');
Object.setPrototypeOf(custom, aggregateError);

assert.strictEqual(
util.inspect(custom),
'[AggregateError: No own errors property]'
);

const cause = [new Error('cause')];
const causeError = new TypeError('Foobar', { cause: [new Error('cause')] });

assert.strictEqual(
util.inspect(causeError),
'[TypeError: Foobar] { [cause]: [ [Error: cause] ] }'
);

const custom2 = new Error('No own cause property');
Object.setPrototypeOf(custom2, causeError);

assert.deepStrictEqual(custom2.cause, cause);
assert.strictEqual(
util.inspect(custom2),
'[TypeError: No own cause property]'
);

Error.stackTraceLimit = stackTraceLimit;
}

{
const tmp = Error.stackTraceLimit;
// Force stackTraceLimit = 0 for this test, but make it non-enumerable
Expand Down
Loading