11cb0ef41Sopenharmony_ci// Flags: --expose-internals
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_cirequire('../common');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ciconst { aggregateTwoErrors } = require('internal/errors');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciassert.strictEqual(aggregateTwoErrors(null, null), null);
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci{
111cb0ef41Sopenharmony_ci  const err = new Error();
121cb0ef41Sopenharmony_ci  assert.strictEqual(aggregateTwoErrors(null, err), err);
131cb0ef41Sopenharmony_ci}
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci{
161cb0ef41Sopenharmony_ci  const err = new Error();
171cb0ef41Sopenharmony_ci  assert.strictEqual(aggregateTwoErrors(err, null), err);
181cb0ef41Sopenharmony_ci}
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci{
211cb0ef41Sopenharmony_ci  const err0 = new Error('original');
221cb0ef41Sopenharmony_ci  const err1 = new Error('second error');
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci  err0.code = 'ERR0';
251cb0ef41Sopenharmony_ci  err1.code = 'ERR1';
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci  const chainedError = aggregateTwoErrors(err1, err0);
281cb0ef41Sopenharmony_ci  assert.strictEqual(chainedError.message, err0.message);
291cb0ef41Sopenharmony_ci  assert.strictEqual(chainedError.code, err0.code);
301cb0ef41Sopenharmony_ci  assert.deepStrictEqual(chainedError.errors, [err0, err1]);
311cb0ef41Sopenharmony_ci}
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci{
341cb0ef41Sopenharmony_ci  const err0 = new Error('original');
351cb0ef41Sopenharmony_ci  const err1 = new Error('second error');
361cb0ef41Sopenharmony_ci  const err2 = new Error('third error');
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci  err0.code = 'ERR0';
391cb0ef41Sopenharmony_ci  err1.code = 'ERR1';
401cb0ef41Sopenharmony_ci  err2.code = 'ERR2';
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci  const chainedError = aggregateTwoErrors(err2, aggregateTwoErrors(err1, err0));
431cb0ef41Sopenharmony_ci  assert.strictEqual(chainedError.message, err0.message);
441cb0ef41Sopenharmony_ci  assert.strictEqual(chainedError.code, err0.code);
451cb0ef41Sopenharmony_ci  assert.deepStrictEqual(chainedError.errors, [err0, err1, err2]);
461cb0ef41Sopenharmony_ci}
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci{
491cb0ef41Sopenharmony_ci  const err0 = new Error('original');
501cb0ef41Sopenharmony_ci  const err1 = new Error('second error');
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci  err0.code = 'ERR0';
531cb0ef41Sopenharmony_ci  err1.code = 'ERR1';
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci  const chainedError = aggregateTwoErrors(null, aggregateTwoErrors(err1, err0));
561cb0ef41Sopenharmony_ci  assert.strictEqual(chainedError.message, err0.message);
571cb0ef41Sopenharmony_ci  assert.strictEqual(chainedError.code, err0.code);
581cb0ef41Sopenharmony_ci  assert.deepStrictEqual(chainedError.errors, [err0, err1]);
591cb0ef41Sopenharmony_ci}
60