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