GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • lib/internal/util
    • inspect.js
  • test
    • message
      • util-inspect-error-cause.js
      • util-inspect-error-cause.out
    • parallel
      • test-util-inspect.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/util/inspect.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ function formatError(err, constructor, tag, ctx, keys) {
12821282

12831283
removeDuplicateErrorKeys(ctx, keys, err, stack);
12841284

1285-
if (err.cause !== undefined &&
1285+
if ('cause' in err &&
12861286
(keys.length === 0 || !keys.includes('cause'))) {
12871287
keys.push('cause');
12881288
}
Collapse file

‎test/message/util-inspect-error-cause.js‎

Copy file name to clipboardExpand all lines: test/message/util-inspect-error-cause.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ const cause5 = new Error('Object cause', {
2222
' at Module._compile (node:internal/modules/cjs/loader:827:30)'
2323
}
2424
});
25+
const cause6 = new Error('undefined cause', {
26+
cause: undefined
27+
});
2528

2629
console.log(cause4);
2730
console.log(cause5);
31+
console.log(cause6);
2832

2933
process.nextTick(() => {
3034
const error = new RangeError('New Stack Frames', { cause: cause2 });
Collapse file

‎test/message/util-inspect-error-cause.out‎

Copy file name to clipboardExpand all lines: test/message/util-inspect-error-cause.out
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ Error: Object cause
2323
' at Module._compile (node:internal/modules/cjs/loader:827:30)'
2424
}
2525
}
26+
Error: undefined cause
27+
at *
28+
at *
29+
at *
30+
at *
31+
at *
32+
at *
33+
at * {
34+
[cause]: undefined
35+
}
2636
RangeError: New Stack Frames
2737
at *
2838
*[90m at *[39m {
Collapse file

‎test/parallel/test-util-inspect.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,15 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
665665
delete falsyCause1.stack;
666666
const falsyCause2 = new Error(undefined, { cause: null });
667667
falsyCause2.stack = '';
668+
const undefinedCause = new Error('', { cause: undefined });
669+
undefinedCause.stack = '';
668670

669671
assert.strictEqual(util.inspect(falsyCause1), '[Error] { [cause]: false }');
670672
assert.strictEqual(util.inspect(falsyCause2), '[Error] { [cause]: null }');
673+
assert.strictEqual(
674+
util.inspect(undefinedCause),
675+
'[Error] { [cause]: undefined }'
676+
);
671677
}
672678

673679
{

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.