Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errors,repl: migrate to use internal/errors.js #13299

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,15 @@ E('ERR_INVALID_TUPLE', '%s must be an iterable %s tuple');
E('ERR_INVALID_URL', 'Invalid URL: %s');
E('ERR_INVALID_URL_SCHEME',
(expected) => `The URL must be ${oneOf(expected, 'scheme')}`);
E('ERR_INVALID_REPL_HISTORY',
(repl_history) => `Expected array, got ${repl_history}`);
E('ERR_IPC_CHANNEL_CLOSED', 'channel closed');
E('ERR_IPC_DISCONNECTED', 'IPC channel is already disconnected');
E('ERR_IPC_ONE_PIPE', 'Child process can have only one IPC pipe');
E('ERR_IPC_SYNC_FORK', 'IPC cannot be used with synchronous forks');
E('ERR_MISSING_ARGS', missingArgs);
E('ERR_PARSE_HISTORY_DATA',
(oldHistoryPath) => `Could not parse history data in ${oldHistoryPath}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit, but it's a bit odd to have one of the new codes use %s while the other uses a template string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasnell I have used template string. So, do you want me to convert it to %s?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would switch the ERR_INVALID_REPL_HISTORY one to use a template string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasnell Done.

E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed');
E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed');
E('ERR_UNKNOWN_BUILTIN_MODULE', (id) => `No such built-in module: ${id}`);
Expand Down
6 changes: 4 additions & 2 deletions lib/internal/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const fs = require('fs');
const os = require('os');
const util = require('util');
const debug = util.debuglog('repl');
const errors = require('internal/errors');

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

if (!Array.isArray(repl.history)) {
throw new Error('Expected array, got ' + typeof repl.history);
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
typeof repl.history, 'Array');
}
repl.history = repl.history.slice(0, repl.historySize);
} catch (err) {
if (err.code !== 'ENOENT') {
return ready(
new Error(`Could not parse history data in ${oldHistoryPath}.`));
new errors.Error('ERR_PARSE_HISTORY_DATA', oldHistoryPath));
}
}
}
Expand Down