diff --git a/doc/api/errors.md b/doc/api/errors.md
index fab75e9bc45fe0..d2e40e90091d3e 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
+
+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 ab0d2fe54eb5da..966ae8e77ef556 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -440,6 +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`.');
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..3c8ca7944cb0eb 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -315,7 +315,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: '' });
}
@@ -335,7 +335,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);
});
@@ -354,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: '' });
}
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
]);
}