• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// The goal of this test is to make sure that when a top-level error
4// handler throws an error following the handling of a previous error,
5// the process reports the error message from the error thrown in the
6// top-level error handler, not the one from the previous error.
7
8require('../common');
9
10const domainErrHandlerExMessage = 'exception from domain error handler';
11const internalExMessage = 'You should NOT see me';
12
13if (process.argv[2] === 'child') {
14  const domain = require('domain');
15  const d = domain.create();
16
17  d.on('error', function() {
18    throw new Error(domainErrHandlerExMessage);
19  });
20
21  d.run(function doStuff() {
22    process.nextTick(function() {
23      throw new Error(internalExMessage);
24    });
25  });
26} else {
27  const fork = require('child_process').fork;
28  const assert = require('assert');
29
30  const child = fork(process.argv[1], ['child'], { silent: true });
31  let stderrOutput = '';
32  if (child) {
33    child.stderr.on('data', function onStderrData(data) {
34      stderrOutput += data.toString();
35    });
36
37    child.on('close', function onChildClosed() {
38      assert(stderrOutput.includes(domainErrHandlerExMessage));
39      assert.strictEqual(stderrOutput.includes(internalExMessage), false);
40    });
41
42    child.on('exit', function onChildExited(exitCode, signal) {
43      const expectedExitCode = 7;
44      const expectedSignal = null;
45
46      assert.strictEqual(exitCode, expectedExitCode);
47      assert.strictEqual(signal, expectedSignal);
48    });
49  }
50}
51