diff --git a/doc/api/errors.md b/doc/api/errors.md
index e521796edd..c72f658989 100644
--- a/doc/api/errors.md
+++ b/doc/api/errors.md
@@ -594,6 +594,12 @@ an argument of the wrong type has been passed to a Node.js API.
The `'ERR_INVALID_CALLBACK'` error code is used generically to identify that
a callback function is required and has not been provided to a Node.js API.
+
+### ERR_INVALID_CURSOR_POS
+
+The `'ERR_INVALID_CURSOR_POS'` is thrown specifically when a cursor on a given
+stream is attempted to move to a specified row without a specified column.
+
### ERR_INVALID_FILE_URL_HOST
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index 1f1dd82c37..957262f008 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -124,6 +124,8 @@ E('ERR_INDEX_OUT_OF_RANGE', 'Index out of range');
E('ERR_INVALID_ARG_TYPE', invalidArgType);
E('ERR_INVALID_CALLBACK', 'callback must be a function');
E('ERR_INVALID_FD', (fd) => `"fd" must be a positive integer: ${fd}`);
+E('ERR_INVALID_CURSOR_POS',
+ 'Cannot set cursor row without setting its column');
E('ERR_INVALID_FILE_URL_HOST', 'File URL host %s');
E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s');
E('ERR_INVALID_HANDLE_TYPE', 'This handle type cannot be sent');
diff --git a/lib/readline.js b/lib/readline.js
index 60864f40af..adf2d5f067 100644
--- a/lib/readline.js
+++ b/lib/readline.js
@@ -27,6 +27,7 @@
'use strict';
+const errors = require('internal/errors');
const { debug, inherits } = require('util');
const Buffer = require('buffer').Buffer;
const EventEmitter = require('events');
@@ -95,7 +96,7 @@ function Interface(input, output, completer, terminal) {
}
if (completer && typeof completer !== 'function') {
- throw new TypeError('Argument "completer" must be a function');
+ throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'completer', completer);
}
if (historySize === undefined) {
@@ -105,7 +106,11 @@ function Interface(input, output, completer, terminal) {
if (typeof historySize !== 'number' ||
isNaN(historySize) ||
historySize < 0) {
- throw new TypeError('Argument "historySize" must be a positive number');
+ throw new errors.RangeError(
+ 'ERR_INVALID_OPT_VALUE',
+ 'historySize',
+ historySize
+ );
}
// backwards compat; check the isTTY prop of the output stream
@@ -281,7 +286,12 @@ Interface.prototype._onLine = function(line) {
Interface.prototype._writeToOutput = function _writeToOutput(stringToWrite) {
if (typeof stringToWrite !== 'string')
- throw new TypeError('"stringToWrite" argument must be a string');
+ throw new errors.TypeError(
+ 'ERR_INVALID_ARG_TYPE',
+ 'stringToWrite',
+ 'string',
+ stringToWrite
+ );
if (this.output !== null && this.output !== undefined)
this.output.write(stringToWrite);
@@ -1053,7 +1063,7 @@ function cursorTo(stream, x, y) {
return;
if (typeof x !== 'number')
- throw new Error('Can\'t set cursor row without also setting it\'s column');
+ throw new errors.Error('ERR_INVALID_CURSOR_POS');
if (typeof y !== 'number') {
stream.write(CSI`${x + 1}G`);
diff --git a/test/parallel/test-readline-csi.js b/test/parallel/test-readline-csi.js
index bde37138e3..d839487643 100644
--- a/test/parallel/test-readline-csi.js
+++ b/test/parallel/test-readline-csi.js
@@ -77,7 +77,8 @@ assert.throws(
() => readline.cursorTo(writable, 'a', 1),
common.expectsError({
type: Error,
- message: /^Can't set cursor row without also setting it's column$/
+ code: 'ERR_INVALID_CURSOR_POS',
+ message: 'Cannot set cursor row without setting its column'
}));
assert.strictEqual(writable.data, '');
diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js
index 6f8849a322..5d77119cdd 100644
--- a/test/parallel/test-readline-interface.js
+++ b/test/parallel/test-readline-interface.js
@@ -315,14 +315,10 @@ function isWarned(emitter) {
input: fi,
completer: 'string is not valid'
});
- }, function(err) {
- if (err instanceof TypeError) {
- if (/Argument "completer" must be a function/.test(err)) {
- return true;
- }
- }
- return false;
- });
+ }, common.expectsError({
+ type: TypeError,
+ code: 'ERR_INVALID_OPT_VALUE'
+ }));
// duplicate lines are removed from history when
// `options.removeHistoryDuplicates` is `true`