GeezerVison is showing github.com — util: display a present-but-undefined error cause · nodejs/node@ab5e94c
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1282,7 +1282,7 @@ function formatError(err, constructor, tag, ctx, keys) { |
1282 | 1282 |
|
1283 | 1283 | removeDuplicateErrorKeys(ctx, keys, err, stack); |
1284 | 1284 |
|
1285 | | - if (err.cause !== undefined && |
| 1285 | + if ('cause' in err && |
1286 | 1286 | (keys.length === 0 || !keys.includes('cause'))) { |
1287 | 1287 | keys.push('cause'); |
1288 | 1288 | } |
|
Collapse file
Copy file name to clipboardExpand all lines: test/message/util-inspect-error-cause.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,9 +22,13 @@ const cause5 = new Error('Object cause', { |
22 | 22 | ' at Module._compile (node:internal/modules/cjs/loader:827:30)' |
23 | 23 | } |
24 | 24 | }); |
| 25 | +const cause6 = new Error('undefined cause', { |
| 26 | + cause: undefined |
| 27 | +}); |
25 | 28 |
|
26 | 29 | console.log(cause4); |
27 | 30 | console.log(cause5); |
| 31 | +console.log(cause6); |
28 | 32 |
|
29 | 33 | process.nextTick(() => { |
30 | 34 | const error = new RangeError('New Stack Frames', { cause: cause2 }); |
|
Collapse file
Copy file name to clipboardExpand all lines: test/message/util-inspect-error-cause.out +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,6 +23,16 @@ Error: Object cause |
23 | 23 | ' at Module._compile (node:internal/modules/cjs/loader:827:30)' |
24 | 24 | } |
25 | 25 | } |
| 26 | +Error: undefined cause |
| 27 | + at * |
| 28 | + at * |
| 29 | + at * |
| 30 | + at * |
| 31 | + at * |
| 32 | + at * |
| 33 | + at * { |
| 34 | + [cause]: undefined |
| 35 | +} |
26 | 36 | RangeError: New Stack Frames |
27 | 37 | at * |
28 | 38 | *[90m at *[39m { |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect.js +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -665,9 +665,15 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); |
665 | 665 | delete falsyCause1.stack; |
666 | 666 | const falsyCause2 = new Error(undefined, { cause: null }); |
667 | 667 | falsyCause2.stack = ''; |
| 668 | + const undefinedCause = new Error('', { cause: undefined }); |
| 669 | + undefinedCause.stack = ''; |
668 | 670 |
|
669 | 671 | assert.strictEqual(util.inspect(falsyCause1), '[Error] { [cause]: false }'); |
670 | 672 | assert.strictEqual(util.inspect(falsyCause2), '[Error] { [cause]: null }'); |
| 673 | + assert.strictEqual( |
| 674 | + util.inspect(undefinedCause), |
| 675 | + '[Error] { [cause]: undefined }' |
| 676 | + ); |
671 | 677 | } |
672 | 678 |
|
673 | 679 | { |
|