| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 09ccd94 commit 6acc9d7
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1703,15 +1703,15 @@ function formatError(err, constructor, tag, ctx, keys) { | |||
| 1703 | 1703 | } | |
| 1704 | 1704 | name ??= 'Error'; | |
| 1705 | 1705 | ||
| 1706 | - if ('cause' in err && | ||
| 1706 | + if (ObjectPrototypeHasOwnProperty(err, 'cause') && | ||
| 1707 | 1707 | (keys.length === 0 || !ArrayPrototypeIncludes(keys, 'cause'))) { | |
| 1708 | 1708 | ArrayPrototypePush(keys, 'cause'); | |
| 1709 | 1709 | } | |
| 1710 | 1710 | ||
| 1711 | 1711 | // Print errors aggregated into AggregateError | |
| 1712 | 1712 | try { | |
| 1713 | 1713 | const errors = err.errors; | |
| 1714 | - if (ArrayIsArray(errors) && | ||
| 1714 | + if (ArrayIsArray(errors) && ObjectPrototypeHasOwnProperty(err, 'errors') && | ||
| 1715 | 1715 | (keys.length === 0 || !ArrayPrototypeIncludes(keys, 'errors'))) { | |
| 1716 | 1716 | ArrayPrototypePush(keys, 'errors'); | |
| 1717 | 1717 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -688,6 +688,53 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); | |||
| 688 | 688 | ); | |
| 689 | 689 | } | |
| 690 | 690 | ||
| 691 | + { | ||
| 692 | + // No own errors or cause property. | ||
| 693 | + const { stackTraceLimit } = Error; | ||
| 694 | + Error.stackTraceLimit = 0; | ||
| 695 | + | ||
| 696 | + const e1 = new Error('e1'); | ||
| 697 | + const e2 = new TypeError('e2'); | ||
| 698 | + const e3 = false; | ||
| 699 | + | ||
| 700 | + const errors = [e1, e2, e3]; | ||
| 701 | + const aggregateError = new AggregateError(errors, 'Foobar'); | ||
| 702 | + | ||
| 703 | + assert.deepStrictEqual(aggregateError.errors, errors); | ||
| 704 | + assert.strictEqual( | ||
| 705 | + util.inspect(aggregateError), | ||
| 706 | + '[AggregateError: Foobar] {\n [errors]: [ [Error: e1], [TypeError: e2], false ]\n}' | ||
| 707 | + ); | ||
| 708 | + | ||
| 709 | + | ||
| 710 | + const custom = new Error('No own errors property'); | ||
| 711 | + Object.setPrototypeOf(custom, aggregateError); | ||
| 712 | + | ||
| 713 | + assert.strictEqual( | ||
| 714 | + util.inspect(custom), | ||
| 715 | + '[AggregateError: No own errors property]' | ||
| 716 | + ); | ||
| 717 | + | ||
| 718 | + const cause = [new Error('cause')]; | ||
| 719 | + const causeError = new TypeError('Foobar', { cause: [new Error('cause')] }); | ||
| 720 | + | ||
| 721 | + assert.strictEqual( | ||
| 722 | + util.inspect(causeError), | ||
| 723 | + '[TypeError: Foobar] { [cause]: [ [Error: cause] ] }' | ||
| 724 | + ); | ||
| 725 | + | ||
| 726 | + const custom2 = new Error('No own cause property'); | ||
| 727 | + Object.setPrototypeOf(custom2, causeError); | ||
| 728 | + | ||
| 729 | + assert.deepStrictEqual(custom2.cause, cause); | ||
| 730 | + assert.strictEqual( | ||
| 731 | + util.inspect(custom2), | ||
| 732 | + '[TypeError: No own cause property]' | ||
| 733 | + ); | ||
| 734 | + | ||
| 735 | + Error.stackTraceLimit = stackTraceLimit; | ||
| 736 | + } | ||
| 737 | + | ||
| 691 | 738 | { | |
| 692 | 739 | const tmp = Error.stackTraceLimit; | |
| 693 | 740 | // Force stackTraceLimit = 0 for this test, but make it non-enumerable | |
| Back | FazBrowse Home | New Git URL |
0 commit comments