Skip to content

Commit ab5a2ab

Browse files
kysnmmaclover7
authored andcommitted
repl: migrate errors to internal/errors
PR-URL: #17716 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 0b0a4fc commit ab5a2ab

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

doc/api/errors.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,11 @@ The `REPL` module was unable parse data from the REPL history file.
13481348
13491349
An attempt was made to `require()` an [ES6 module][].
13501350

1351+
<a id="ERR_SCRIPT_EXECUTION_INTERRUPTED"></a>
1352+
### ERR_SCRIPT_EXECUTION_INTERRUPTED
1353+
1354+
Script execution was interrupted by `SIGINT` (For example, when Ctrl+C was pressed).
1355+
13511356
<a id="ERR_SERVER_ALREADY_LISTEN"></a>
13521357
### ERR_SERVER_ALREADY_LISTEN
13531358

lib/internal/errors.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ E('ERR_OUTOFMEMORY', 'Out of memory');
445445
E('ERR_OUT_OF_RANGE', 'The "%s" argument is out of range');
446446
E('ERR_PARSE_HISTORY_DATA', 'Could not parse history data in %s');
447447
E('ERR_REQUIRE_ESM', 'Must use import to load ES Module: %s');
448+
E('ERR_SCRIPT_EXECUTION_INTERRUPTED',
449+
'Script execution was interrupted by `SIGINT`.');
448450
E('ERR_SERVER_ALREADY_LISTEN',
449451
'Listen method has been called more than once without closing.');
450452
E('ERR_SOCKET_ALREADY_BOUND', 'Socket is already bound');

lib/repl.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ function REPLServer(prompt,
319319
} catch (e) {
320320
err = e;
321321

322-
if (err && err.message === 'Script execution interrupted.') {
322+
if (err && err.code === 'ERR_SCRIPT_EXECUTION_INTERRUPTED') {
323323
// The stack trace for this case is not very useful anyway.
324324
Object.defineProperty(err, 'stack', { value: '' });
325325
}
@@ -339,7 +339,7 @@ function REPLServer(prompt,
339339
if (self.breakEvalOnSigint) {
340340
const interrupt = new Promise((resolve, reject) => {
341341
sigintListener = () => {
342-
reject(new Error('Script execution interrupted.'));
342+
reject(new errors.Error('ERR_SCRIPT_EXECUTION_INTERRUPTED'));
343343
};
344344
prioritizedSigintQueue.add(sigintListener);
345345
});
@@ -358,7 +358,7 @@ function REPLServer(prompt,
358358
// Remove prioritized SIGINT listener if it was not called.
359359
prioritizedSigintQueue.delete(sigintListener);
360360

361-
if (err.message === 'Script execution interrupted.') {
361+
if (err.code === 'ERR_SCRIPT_EXECUTION_INTERRUPTED') {
362362
// The stack trace for this case is not very useful anyway.
363363
Object.defineProperty(err, 'stack', { value: '' });
364364
}

test/parallel/test-repl-top-level-await.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ async function ctrlCTest() {
160160
{ ctrl: true, name: 'c' }
161161
]), [
162162
'await timeout(100000)\r',
163-
'Thrown: Error: Script execution interrupted.',
163+
'Thrown: Error [ERR_SCRIPT_EXECUTION_INTERRUPTED]: ' +
164+
'Script execution was interrupted by `SIGINT`.',
164165
PROMPT
165166
]);
166167
}

0 commit comments

Comments
 (0)