Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 33 additions & 0 deletions test/fixtures/util/util-inspect-error-cause.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

require('../../common');

const { inspect } = require('util');

class FoobarError extends Error {
status = 'Feeling good';
}

const cause1 = new TypeError('Inner error');
const cause2 = new FoobarError('Individual message', { cause: cause1 });
cause2.extraProperties = 'Yes!';
const cause3 = new Error('Stack causes', { cause: cause2 });

const cause4 = new Error('Number error cause', { cause: 42 });
const cause5 = new Error('Object cause', {
cause: {
message: 'Unique',
name: 'Error',
stack: 'Error: Unique\n' +
' at Module._compile (node:internal/modules/cjs/loader:827:30)',
},
});
const cause6 = new Error('undefined cause', {
cause: undefined,
});

console.log(cause4);
console.log(cause5);
console.log(cause6);
console.log(cause3);
console.log(inspect(cause3, { compact: false, breakLength: Infinity }));
69 changes: 69 additions & 0 deletions test/fixtures/util/util-inspect-error-cause.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Error: Number error cause
at *
at *
at *
at *
at *
at *
at *
at * {
[cause]: 42
}
Error: Object cause
at *
at *
at *
at *
at *
at *
at *
at * {
[cause]: {
message: 'Unique',
name: 'Error',
stack: 'Error: Unique\n' +
' at Module._compile (node:internal*modules*cjs*loader:*:*)'
}
}
Error: undefined cause
at *
at *
at *
at *
at *
at *
at *
at * {
[cause]: undefined
}
Error: Stack causes
at *
at *
at *
at *
at *
at *
at *
at * {
[cause]: FoobarError: Individual message
at *
at *
at *
at *
at *
at *
at *
at * {
status: 'Feeling good',
extraProperties: 'Yes!',
[cause]: TypeError: Inner error
at *
at *
at *
at *
at *
at *
at *
at *
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

require('../common');
require('../../common');
const util = require('util');

const err = new Error('foo\nbar');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
at *
nested:
{ err:
Error: foo
bar
at *util_inspect_error*
at *
at *
at *
at *
at *
at *
at *
Error: foo
bar
at *util_inspect_error*
at *
at *
at *
at *
at *
at *
at * } }
{
err: Error: foo
bar
Expand All @@ -31,7 +31,7 @@
at *
at *
at *
at *
at *,
nested: {
err: Error: foo
bar
Expand All @@ -45,7 +45,7 @@
at *
}
}
{ Error: foo
Error: foo
bar
at *util_inspect_error*
at *
Expand All @@ -54,5 +54,6 @@ bar
at *
at *
at *
at *
foo: 'bar' }
at * {
foo: 'bar'
}
54 changes: 0 additions & 54 deletions test/message/util-inspect-error-cause.js

This file was deleted.

Loading
Loading