From ab5a2aba38c7de995d7bb56750ab90c0c7849157 Mon Sep 17 00:00:00 2001 From: kysnm Date: Sun, 17 Dec 2017 20:29:35 +0900 Subject: [PATCH] repl: migrate errors to internal/errors PR-URL: https://github.com/nodejs/node/pull/17716 Reviewed-By: James M Snell Reviewed-By: Joyee Cheung Reviewed-By: Matteo Collina Reviewed-By: Jon Moss Reviewed-By: Ruben Bridgewater --- doc/api/errors.md | 5 +++++ lib/internal/errors.js | 2 ++ lib/repl.js | 6 +++--- test/parallel/test-repl-top-level-await.js | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 918cfa343136af..4f7e2651c93471 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1348,6 +1348,11 @@ The `REPL` module was unable parse data from the REPL history file. An attempt was made to `require()` an [ES6 module][]. + +### ERR_SCRIPT_EXECUTION_INTERRUPTED + +Script execution was interrupted by `SIGINT` (For example, when Ctrl+C was pressed). + ### ERR_SERVER_ALREADY_LISTEN diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 7276bb6344a5bd..5b18a7026e0396 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -445,6 +445,8 @@ E('ERR_OUTOFMEMORY', 'Out of memory'); E('ERR_OUT_OF_RANGE', 'The "%s" argument is out of range'); E('ERR_PARSE_HISTORY_DATA', 'Could not parse history data in %s'); E('ERR_REQUIRE_ESM', 'Must use import to load ES Module: %s'); +E('ERR_SCRIPT_EXECUTION_INTERRUPTED', + 'Script execution was interrupted by `SIGINT`.'); E('ERR_SERVER_ALREADY_LISTEN', 'Listen method has been called more than once without closing.'); E('ERR_SOCKET_ALREADY_BOUND', 'Socket is already bound'); diff --git a/lib/repl.js b/lib/repl.js index 0378a6664c43e4..98fd78eacaa5e5 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -319,7 +319,7 @@ function REPLServer(prompt, } catch (e) { err = e; - if (err && err.message === 'Script execution interrupted.') { + if (err && err.code === 'ERR_SCRIPT_EXECUTION_INTERRUPTED') { // The stack trace for this case is not very useful anyway. Object.defineProperty(err, 'stack', { value: '' }); } @@ -339,7 +339,7 @@ function REPLServer(prompt, if (self.breakEvalOnSigint) { const interrupt = new Promise((resolve, reject) => { sigintListener = () => { - reject(new Error('Script execution interrupted.')); + reject(new errors.Error('ERR_SCRIPT_EXECUTION_INTERRUPTED')); }; prioritizedSigintQueue.add(sigintListener); }); @@ -358,7 +358,7 @@ function REPLServer(prompt, // Remove prioritized SIGINT listener if it was not called. prioritizedSigintQueue.delete(sigintListener); - if (err.message === 'Script execution interrupted.') { + if (err.code === 'ERR_SCRIPT_EXECUTION_INTERRUPTED') { // The stack trace for this case is not very useful anyway. Object.defineProperty(err, 'stack', { value: '' }); } diff --git a/test/parallel/test-repl-top-level-await.js b/test/parallel/test-repl-top-level-await.js index 2d6b32b4003853..a7edb66a81a1f8 100644 --- a/test/parallel/test-repl-top-level-await.js +++ b/test/parallel/test-repl-top-level-await.js @@ -160,7 +160,8 @@ async function ctrlCTest() { { ctrl: true, name: 'c' } ]), [ 'await timeout(100000)\r', - 'Thrown: Error: Script execution interrupted.', + 'Thrown: Error [ERR_SCRIPT_EXECUTION_INTERRUPTED]: ' + + 'Script execution was interrupted by `SIGINT`.', PROMPT ]); }