Skip to content

Commit 79acbdb

Browse files
committed
errors, repl: migrate to use internal/errors.js
* Use existing errors where suitable * Assign code to a REPL specific error * Include documentation for the new error code
1 parent b1ed55f commit 79acbdb

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

doc/api/errors.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,12 @@ process. See [`child.send()`] and [`process.send()`] for more information.
624624
The `'ERR_INVALID_OPT_VALUE'` error code is used generically to identify when
625625
an invalid or unexpected value has been passed in an options object.
626626

627+
<a id="ERR_INVALID_REPL_EVAL_CONFIG"></a>
628+
### ERR_INVALID_REPL_EVAL_CONFIG
629+
630+
Used when both `breakEvalOnSigint` and `eval` options are set
631+
in the REPL config, which is not supported.
632+
627633
<a id="ERR_INVALID_SYNC_FORK_INPUT"></a>
628634
### ERR_INVALID_SYNC_FORK_INPUT
629635

lib/internal/errors.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ E('ERR_INVALID_OPT_VALUE',
129129
(name, value) => {
130130
return `The value "${String(value)}" is invalid for option "${name}"`;
131131
});
132+
E('ERR_INVALID_REPL_EVAL_CONFIG',
133+
'Cannot specify both "breakEvalOnSigint" and "eval" for REPL');
132134
E('ERR_INVALID_SYNC_FORK_INPUT',
133135
(value) => {
134136
return 'Asynchronous forks do not support Buffer, Uint8Array or string' +

lib/repl.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const Console = require('console').Console;
5656
const Module = require('module');
5757
const domain = require('domain');
5858
const debug = util.debuglog('repl');
59+
const errors = require('internal/errors');
5960

6061
const parentModule = module;
6162
const replMap = new WeakMap();
@@ -138,7 +139,7 @@ function REPLServer(prompt,
138139
if (breakEvalOnSigint && eval_) {
139140
// Allowing this would not reflect user expectations.
140141
// breakEvalOnSigint affects only the behaviour of the default eval().
141-
throw new Error('Cannot specify both breakEvalOnSigint and eval for REPL');
142+
throw new errors.Error('ERR_INVALID_REPL_EVAL_CONFIG');
142143
}
143144

144145
var self = this;
@@ -1021,7 +1022,8 @@ REPLServer.prototype.defineCommand = function(keyword, cmd) {
10211022
if (typeof cmd === 'function') {
10221023
cmd = {action: cmd};
10231024
} else if (typeof cmd.action !== 'function') {
1024-
throw new Error('Bad argument, "action" command must be a function');
1025+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
1026+
'action', 'function', cmd.action);
10251027
}
10261028
this.commands[keyword] = cmd;
10271029
};

0 commit comments

Comments
 (0)