0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-error-aggregateTwoErrors.js
Aras Abbasi 83e6350b82
errors: improve hideStackFrames
PR-URL: https://github.com/nodejs/node/pull/49990
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-11-11 16:25:08 +00:00

72 lines
1.8 KiB
JavaScript

// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const { aggregateTwoErrors } = require('internal/errors');
assert.strictEqual(aggregateTwoErrors(null, null), null);
{
const err = new Error();
assert.strictEqual(aggregateTwoErrors(null, err), err);
}
{
const err = new Error();
assert.strictEqual(aggregateTwoErrors(err, null), err);
}
{
const err0 = new Error('original');
const err1 = new Error('second error');
err0.code = 'ERR0';
err1.code = 'ERR1';
const chainedError = aggregateTwoErrors(err1, err0);
assert.strictEqual(chainedError.message, err0.message);
assert.strictEqual(chainedError.code, err0.code);
assert.deepStrictEqual(chainedError.errors, [err0, err1]);
}
{
const err0 = new Error('original');
const err1 = new Error('second error');
const err2 = new Error('third error');
err0.code = 'ERR0';
err1.code = 'ERR1';
err2.code = 'ERR2';
const chainedError = aggregateTwoErrors(err2, aggregateTwoErrors(err1, err0));
assert.strictEqual(chainedError.message, err0.message);
assert.strictEqual(chainedError.code, err0.code);
assert.deepStrictEqual(chainedError.errors, [err0, err1, err2]);
}
{
const err0 = new Error('original');
const err1 = new Error('second error');
err0.code = 'ERR0';
err1.code = 'ERR1';
const chainedError = aggregateTwoErrors(null, aggregateTwoErrors(err1, err0));
assert.strictEqual(chainedError.message, err0.message);
assert.strictEqual(chainedError.code, err0.code);
assert.deepStrictEqual(chainedError.errors, [err0, err1]);
}
{
const err0 = new Error('original');
const err1 = new Error('second error');
err0.code = 'ERR0';
err1.code = 'ERR1';
const chainedError = aggregateTwoErrors(null, aggregateTwoErrors(err1, err0));
const stack = chainedError.stack.split('\n');
assert.match(stack[1], /^ {4}at Object/);
}