Skip to content

Commit 2822796

Browse files
sreepurnajastijasnell
sreepurnajasti
authored andcommitted
errors,repl: migrate to use internal/errors.js
PR-URL: #13299 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 3c989de commit 2822796

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/internal/errors.js

+4
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,15 @@ E('ERR_INVALID_TUPLE', '%s must be an iterable %s tuple');
134134
E('ERR_INVALID_URL', 'Invalid URL: %s');
135135
E('ERR_INVALID_URL_SCHEME',
136136
(expected) => `The URL must be ${oneOf(expected, 'scheme')}`);
137+
E('ERR_INVALID_REPL_HISTORY',
138+
(repl_history) => `Expected array, got ${repl_history}`);
137139
E('ERR_IPC_CHANNEL_CLOSED', 'channel closed');
138140
E('ERR_IPC_DISCONNECTED', 'IPC channel is already disconnected');
139141
E('ERR_IPC_ONE_PIPE', 'Child process can have only one IPC pipe');
140142
E('ERR_IPC_SYNC_FORK', 'IPC cannot be used with synchronous forks');
141143
E('ERR_MISSING_ARGS', missingArgs);
144+
E('ERR_PARSE_HISTORY_DATA',
145+
(oldHistoryPath) => `Could not parse history data in ${oldHistoryPath}`);
142146
E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed');
143147
E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed');
144148
E('ERR_UNKNOWN_BUILTIN_MODULE', (id) => `No such built-in module: ${id}`);

lib/internal/repl.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const fs = require('fs');
77
const os = require('os');
88
const util = require('util');
99
const debug = util.debuglog('repl');
10+
const errors = require('internal/errors');
1011

1112
module.exports = Object.create(REPL);
1213
module.exports.createInternalRepl = createRepl;
@@ -153,13 +154,14 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) {
153154
if (oldReplJSONHistory) repl.history = JSON.parse(oldReplJSONHistory);
154155

155156
if (!Array.isArray(repl.history)) {
156-
throw new Error('Expected array, got ' + typeof repl.history);
157+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
158+
typeof repl.history, 'Array');
157159
}
158160
repl.history = repl.history.slice(0, repl.historySize);
159161
} catch (err) {
160162
if (err.code !== 'ENOENT') {
161163
return ready(
162-
new Error(`Could not parse history data in ${oldHistoryPath}.`));
164+
new errors.Error('ERR_PARSE_HISTORY_DATA', oldHistoryPath));
163165
}
164166
}
165167
}

0 commit comments

Comments
 (0)