From f237327268eb40ddd2d259ea85acdf107d03f60b Mon Sep 17 00:00:00 2001 From: kysnm Date: Sun, 17 Dec 2017 20:29:35 +0900 Subject: [PATCH 1/7] repl: migrate errors to internal/errors --- doc/api/errors.md | 5 +++++ lib/internal/errors.js | 1 + lib/repl.js | 5 +++-- test/parallel/test-internal-errors.js | 7 +++++++ test/parallel/test-repl-top-level-await.js | 4 +++- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index fab75e9bc45fe0..465f1a5dbf8e0d 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1330,6 +1330,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 + +A script execution interrupted. + ### ERR_SERVER_ALREADY_LISTEN diff --git a/lib/internal/errors.js b/lib/internal/errors.js index ab0d2fe54eb5da..cee39e21285f22 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -440,6 +440,7 @@ 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 interrupted.'); 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 da3ed78e9ebab6..20ba2b86e3b907 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -315,7 +315,8 @@ function REPLServer(prompt, } catch (e) { err = e; - if (err && err.message === 'Script execution interrupted.') { + if (err && err.message === + errors.message('ERR_SCRIPT_EXECUTION_INTERRUPTED')) { // The stack trace for this case is not very useful anyway. Object.defineProperty(err, 'stack', { value: '' }); } @@ -335,7 +336,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); }); diff --git a/test/parallel/test-internal-errors.js b/test/parallel/test-internal-errors.js index 78582a53504748..da4a618587db27 100644 --- a/test/parallel/test-internal-errors.js +++ b/test/parallel/test-internal-errors.js @@ -341,6 +341,13 @@ assert.strictEqual( ); } +// Test ERR_SCRIPT_EXECUTION_INTERRUPTED +assert.strictEqual( + errors.message('ERR_SCRIPT_EXECUTION_INTERRUPTED'), + 'Script execution interrupted.' +); + + // Test that `code` property is mutable and that changing it does not change the // name. { diff --git a/test/parallel/test-repl-top-level-await.js b/test/parallel/test-repl-top-level-await.js index 2d6b32b4003853..08501c57ba21f2 100644 --- a/test/parallel/test-repl-top-level-await.js +++ b/test/parallel/test-repl-top-level-await.js @@ -2,6 +2,7 @@ const common = require('../common'); const assert = require('assert'); +const errors = require('internal/errors'); const { stripVTControlCharacters } = require('internal/readline'); const repl = require('repl'); @@ -160,7 +161,8 @@ async function ctrlCTest() { { ctrl: true, name: 'c' } ]), [ 'await timeout(100000)\r', - 'Thrown: Error: Script execution interrupted.', + 'Thrown: Error [ERR_SCRIPT_EXECUTION_INTERRUPTED]: ' + + errors.message('ERR_SCRIPT_EXECUTION_INTERRUPTED'), PROMPT ]); } From 4f918bbcf48193a08f06968fe451620a459d51e8 Mon Sep 17 00:00:00 2001 From: kysnm Date: Mon, 18 Dec 2017 21:58:24 +0900 Subject: [PATCH 2/7] Check the err.code instead of the err.message --- lib/repl.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index 20ba2b86e3b907..3c8ca7944cb0eb 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -315,8 +315,7 @@ function REPLServer(prompt, } catch (e) { err = e; - if (err && err.message === - errors.message('ERR_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: '' }); } @@ -355,7 +354,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: '' }); } From 65fc1e872a31363e24a3c46acd5bf0d465cb7578 Mon Sep 17 00:00:00 2001 From: kysnm Date: Mon, 18 Dec 2017 22:05:06 +0900 Subject: [PATCH 3/7] Remove useless test --- test/parallel/test-internal-errors.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/parallel/test-internal-errors.js b/test/parallel/test-internal-errors.js index da4a618587db27..78582a53504748 100644 --- a/test/parallel/test-internal-errors.js +++ b/test/parallel/test-internal-errors.js @@ -341,13 +341,6 @@ assert.strictEqual( ); } -// Test ERR_SCRIPT_EXECUTION_INTERRUPTED -assert.strictEqual( - errors.message('ERR_SCRIPT_EXECUTION_INTERRUPTED'), - 'Script execution interrupted.' -); - - // Test that `code` property is mutable and that changing it does not change the // name. { From fed6d47230ab4bfc7a7183963c2ae1676d484597 Mon Sep 17 00:00:00 2001 From: kysnm Date: Mon, 18 Dec 2017 22:11:45 +0900 Subject: [PATCH 4/7] Change the contents of the error message in detail --- doc/api/errors.md | 2 +- lib/internal/errors.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 465f1a5dbf8e0d..7eb60b9315c1b9 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1333,7 +1333,7 @@ An attempt was made to `require()` an [ES6 module][]. ### ERR_SCRIPT_EXECUTION_INTERRUPTED -A script execution interrupted. +Script execution was interrupted by `SIGINT` (Ctrl+C). ### ERR_SERVER_ALREADY_LISTEN diff --git a/lib/internal/errors.js b/lib/internal/errors.js index cee39e21285f22..b2795a6cb7e3e6 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -440,7 +440,7 @@ 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 interrupted.'); +E('ERR_SCRIPT_EXECUTION_INTERRUPTED', 'Script execution was interrupted by `SIGINT` (Ctrl+C).'); E('ERR_SERVER_ALREADY_LISTEN', 'Listen method has been called more than once without closing.'); E('ERR_SOCKET_ALREADY_BOUND', 'Socket is already bound'); From 3dcabb706a3cc38104779718580e35c28c3b0319 Mon Sep 17 00:00:00 2001 From: kysnm Date: Mon, 18 Dec 2017 22:17:07 +0900 Subject: [PATCH 5/7] Check the actual error message instead of the generate it --- lib/internal/errors.js | 3 ++- test/parallel/test-repl-top-level-await.js | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/errors.js b/lib/internal/errors.js index b2795a6cb7e3e6..ba7000e4cbbf26 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -440,7 +440,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` (Ctrl+C).'); +E('ERR_SCRIPT_EXECUTION_INTERRUPTED', + 'Script execution was interrupted by `SIGINT` (Ctrl+C).'); 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/test/parallel/test-repl-top-level-await.js b/test/parallel/test-repl-top-level-await.js index 08501c57ba21f2..253252c729ef93 100644 --- a/test/parallel/test-repl-top-level-await.js +++ b/test/parallel/test-repl-top-level-await.js @@ -2,7 +2,6 @@ const common = require('../common'); const assert = require('assert'); -const errors = require('internal/errors'); const { stripVTControlCharacters } = require('internal/readline'); const repl = require('repl'); @@ -162,7 +161,7 @@ async function ctrlCTest() { ]), [ 'await timeout(100000)\r', 'Thrown: Error [ERR_SCRIPT_EXECUTION_INTERRUPTED]: ' + - errors.message('ERR_SCRIPT_EXECUTION_INTERRUPTED'), + 'Script execution was interrupted by `SIGINT` (Ctrl+C).', PROMPT ]); } From 480358bbc09a889c7e8a06489ff7da360c8badde Mon Sep 17 00:00:00 2001 From: kysnm Date: Tue, 19 Dec 2017 21:18:05 +0900 Subject: [PATCH 6/7] Describe more details at the docs. --- doc/api/errors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 7eb60b9315c1b9..d2e40e90091d3e 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1333,7 +1333,7 @@ An attempt was made to `require()` an [ES6 module][]. ### ERR_SCRIPT_EXECUTION_INTERRUPTED -Script execution was interrupted by `SIGINT` (Ctrl+C). +Script execution was interrupted by `SIGINT` (For example, when Ctrl+C was pressed). ### ERR_SERVER_ALREADY_LISTEN From f142f848e3902d8a6df19dd306749ad9d7dea275 Mon Sep 17 00:00:00 2001 From: kysnm Date: Tue, 19 Dec 2017 21:19:00 +0900 Subject: [PATCH 7/7] Remove useless parenthses. --- lib/internal/errors.js | 2 +- test/parallel/test-repl-top-level-await.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/errors.js b/lib/internal/errors.js index ba7000e4cbbf26..966ae8e77ef556 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -441,7 +441,7 @@ 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` (Ctrl+C).'); + '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/test/parallel/test-repl-top-level-await.js b/test/parallel/test-repl-top-level-await.js index 253252c729ef93..a7edb66a81a1f8 100644 --- a/test/parallel/test-repl-top-level-await.js +++ b/test/parallel/test-repl-top-level-await.js @@ -161,7 +161,7 @@ async function ctrlCTest() { ]), [ 'await timeout(100000)\r', 'Thrown: Error [ERR_SCRIPT_EXECUTION_INTERRUPTED]: ' + - 'Script execution was interrupted by `SIGINT` (Ctrl+C).', + 'Script execution was interrupted by `SIGINT`.', PROMPT ]); }