Skip to content

Commit aff8d35

Browse files
no23reasontniessen
authored andcommitted
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 PR-URL: #11347 Ref: #11273 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 37fdfce commit aff8d35

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

doc/api/errors.md

+6
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,12 @@ communication channel to a child process. See [`child.send()`] and
632632
Used generically to identify when an invalid or unexpected value has been
633633
passed in an options object.
634634

635+
<a id="ERR_INVALID_REPL_EVAL_CONFIG"></a>
636+
### ERR_INVALID_REPL_EVAL_CONFIG
637+
638+
Used when both `breakEvalOnSigint` and `eval` options are set
639+
in the REPL config, which is not supported.
640+
635641
<a id="ERR_INVALID_SYNC_FORK_INPUT"></a>
636642
### ERR_INVALID_SYNC_FORK_INPUT
637643

lib/internal/errors.js

+2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ E('ERR_INVALID_OPT_VALUE',
134134
(name, value) => {
135135
return `The value "${String(value)}" is invalid for option "${name}"`;
136136
});
137+
E('ERR_INVALID_REPL_EVAL_CONFIG',
138+
'Cannot specify both "breakEvalOnSigint" and "eval" for REPL');
137139
E('ERR_INVALID_SYNC_FORK_INPUT',
138140
(value) => {
139141
return 'Asynchronous forks do not support Buffer, Uint8Array or string' +

lib/repl.js

+4-2
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;
@@ -1022,7 +1023,8 @@ REPLServer.prototype.defineCommand = function(keyword, cmd) {
10221023
if (typeof cmd === 'function') {
10231024
cmd = {action: cmd};
10241025
} else if (typeof cmd.action !== 'function') {
1025-
throw new Error('Bad argument, "action" command must be a function');
1026+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
1027+
'action', 'function', cmd.action);
10261028
}
10271029
this.commands[keyword] = cmd;
10281030
};

0 commit comments

Comments
 (0)