| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8f46bd9 commit 1dd15c9
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1955,15 +1955,15 @@ function formatError(err, constructor, tag, ctx, keys) { | |||
| 1955 | 1955 | } | |
| 1956 | 1956 | name ??= 'Error'; | |
| 1957 | 1957 | ||
| 1958 | - if ('cause' in err && | ||
| 1958 | + if (ObjectPrototypeHasOwnProperty(err, 'cause') && | ||
| 1959 | 1959 | (keys.length === 0 || !ArrayPrototypeIncludes(keys, 'cause'))) { | |
| 1960 | 1960 | ArrayPrototypePush(keys, 'cause'); | |
| 1961 | 1961 | } | |
| 1962 | 1962 | ||
| 1963 | 1963 | // Print errors aggregated into AggregateError | |
| 1964 | 1964 | try { | |
| 1965 | 1965 | const errors = err.errors; | |
| 1966 | - if (ArrayIsArray(errors) && | ||
| 1966 | + if (ArrayIsArray(errors) && ObjectPrototypeHasOwnProperty(err, 'errors') && | ||
| 1967 | 1967 | (keys.length === 0 || !ArrayPrototypeIncludes(keys, 'errors'))) { | |
| 1968 | 1968 | ArrayPrototypePush(keys, 'errors'); | |
| 1969 | 1969 | } | |
| 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