• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-internals
2'use strict';
3
4require('../common');
5const assert = require('assert');
6const { aggregateTwoErrors } = require('internal/errors');
7
8assert.strictEqual(aggregateTwoErrors(null, null), null);
9
10{
11  const err = new Error();
12  assert.strictEqual(aggregateTwoErrors(null, err), err);
13}
14
15{
16  const err = new Error();
17  assert.strictEqual(aggregateTwoErrors(err, null), err);
18}
19
20{
21  const err0 = new Error('original');
22  const err1 = new Error('second error');
23
24  err0.code = 'ERR0';
25  err1.code = 'ERR1';
26
27  const chainedError = aggregateTwoErrors(err1, err0);
28  assert.strictEqual(chainedError.message, err0.message);
29  assert.strictEqual(chainedError.code, err0.code);
30  assert.deepStrictEqual(chainedError.errors, [err0, err1]);
31}
32
33{
34  const err0 = new Error('original');
35  const err1 = new Error('second error');
36  const err2 = new Error('third error');
37
38  err0.code = 'ERR0';
39  err1.code = 'ERR1';
40  err2.code = 'ERR2';
41
42  const chainedError = aggregateTwoErrors(err2, aggregateTwoErrors(err1, err0));
43  assert.strictEqual(chainedError.message, err0.message);
44  assert.strictEqual(chainedError.code, err0.code);
45  assert.deepStrictEqual(chainedError.errors, [err0, err1, err2]);
46}
47
48{
49  const err0 = new Error('original');
50  const err1 = new Error('second error');
51
52  err0.code = 'ERR0';
53  err1.code = 'ERR1';
54
55  const chainedError = aggregateTwoErrors(null, aggregateTwoErrors(err1, err0));
56  assert.strictEqual(chainedError.message, err0.message);
57  assert.strictEqual(chainedError.code, err0.code);
58  assert.deepStrictEqual(chainedError.errors, [err0, err1]);
59}
60