mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
863ac8fa37
PR-URL: https://github.com/nodejs/node/pull/47163 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
'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);
|
|
|
|
process.nextTick(() => {
|
|
const error = new RangeError('New Stack Frames', { cause: cause2 });
|
|
const error2 = new RangeError('New Stack Frames', { cause: cause3 });
|
|
|
|
inspect.defaultOptions.colors = true;
|
|
|
|
console.log(inspect(error));
|
|
console.log(inspect(cause3));
|
|
console.log(inspect(error2));
|
|
|
|
inspect.defaultOptions.colors = false;
|
|
|
|
console.log(inspect(error));
|
|
console.log(inspect(cause3));
|
|
console.log(inspect(error2));
|
|
});
|
|
|
|
{
|
|
const error = new Error('cause that throws');
|
|
Reflect.defineProperty(error, 'cause', { get() { throw new Error(); } });
|
|
console.log(inspect(error));
|
|
}
|