From 422e8f762873aef4a37185f3237c0d666c929d8e Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 17 May 2018 16:25:36 +0200 Subject: repl: handle uncaughtException properly When running the REPL as standalone program it's now possible to use `process.on('uncaughtException', listener)`. It is going to use those listeners from now on and the regular error output is suppressed. It also fixes the issue that REPL instances started inside of an application would silence all application errors. It is now prohibited to add the exception listener in such REPL instances. Trying to add such listeners throws an `ERR_INVALID_REPL_INPUT` error. Fixes: https://github.com/nodejs/node/issues/19998 PR-URL: https://github.com/nodejs/node/pull/27151 Fixes: https://github.com/nodejs/node/issues/19998 Reviewed-By: Lance Ball Reviewed-By: Rich Trott --- .../test-repl-uncaught-exception-standalone.js | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/parallel/test-repl-uncaught-exception-standalone.js (limited to 'test/parallel/test-repl-uncaught-exception-standalone.js') diff --git a/test/parallel/test-repl-uncaught-exception-standalone.js b/test/parallel/test-repl-uncaught-exception-standalone.js new file mode 100644 index 0000000000..ae7b214fef --- /dev/null +++ b/test/parallel/test-repl-uncaught-exception-standalone.js @@ -0,0 +1,38 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const cp = require('child_process'); +const child = cp.spawn(process.execPath, ['-i']); +let output = ''; + +child.stdout.setEncoding('utf8'); +child.stdout.on('data', (data) => { + output += data; +}); + +child.on('exit', common.mustCall(() => { + const results = output.split('\n'); + results.shift(); + assert.deepStrictEqual( + results, + [ + 'Type ".help" for more information.', + // x\n + '> Thrown:', + 'ReferenceError: x is not defined', + // Added `uncaughtException` listener. + '> short', + 'undefined', + // x\n + '> Foobar', + '> ' + ] + ); +})); + +child.stdin.write('x\n'); +child.stdin.write( + 'process.on("uncaughtException", () => console.log("Foobar"));' + + 'console.log("short")\n'); +child.stdin.write('x\n'); +child.stdin.end(); -- cgit v1.2.3