Skip to content

Commit c179254

Browse files
starkwangevanlucas
authored andcommitted
lib: improve the usage of TypeError[INVALID_ARG_TYPE]
The initials of expected in TypeError[ERR_INVALID_ARG_TYPE] are inconsistent. This change is to unify them. PR-URL: #16401 Fixes: #16383 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 64a0c80 commit c179254

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+96
-96
lines changed

lib/_http_client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function ClientRequest(options, cb) {
105105
// when createConnection is provided.
106106
} else if (typeof agent.addRequest !== 'function') {
107107
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'Agent option',
108-
['Agent-like object', 'undefined', 'false']);
108+
['Agent-like Object', 'undefined', 'false']);
109109
}
110110
this.agent = agent;
111111

lib/_http_outgoing.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
652652

653653
if (!fromEnd && typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
654654
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'first argument',
655-
['string', 'buffer']);
655+
['string', 'Buffer']);
656656
}
657657

658658

@@ -750,7 +750,7 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
750750
if (chunk) {
751751
if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
752752
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'first argument',
753-
['string', 'buffer']);
753+
['string', 'Buffer']);
754754
}
755755
if (!this._header) {
756756
if (typeof chunk === 'string')

lib/_tls_wrap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ function Server(options, listener) {
845845
} else if (options == null || typeof options === 'object') {
846846
options = options || {};
847847
} else {
848-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object');
848+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
849849
}
850850

851851

lib/assert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function innerThrows(shouldThrow, block, expected, message) {
166166
var details = '';
167167

168168
if (typeof block !== 'function') {
169-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'block', 'function',
169+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'block', 'Function',
170170
block);
171171
}
172172

lib/buffer.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Buffer.from = function from(value, encodingOrOffset, length) {
199199
throw new errors.TypeError(
200200
'ERR_INVALID_ARG_TYPE',
201201
'first argument',
202-
['string', 'buffer', 'arrayBuffer', 'array', 'array-like object'],
202+
['string', 'Buffer', 'ArrayBuffer', 'Array', 'Array-like Object'],
203203
value
204204
);
205205
}
@@ -226,7 +226,7 @@ Buffer.from = function from(value, encodingOrOffset, length) {
226226
throw new errors.TypeError(
227227
'ERR_INVALID_ARG_TYPE',
228228
'first argument',
229-
['string', 'buffer', 'arrayBuffer', 'array', 'array-like object'],
229+
['string', 'Buffer', 'ArrayBuffer', 'Array', 'Array-like Object'],
230230
value
231231
);
232232
};
@@ -429,7 +429,7 @@ Buffer.isBuffer = function isBuffer(b) {
429429
Buffer.compare = function compare(a, b) {
430430
if (!isUint8Array(a) || !isUint8Array(b)) {
431431
throw new errors.TypeError(
432-
'ERR_INVALID_ARG_TYPE', ['buf1', 'buf2'], ['buffer', 'uint8Array']
432+
'ERR_INVALID_ARG_TYPE', ['buf1', 'buf2'], ['Buffer', 'Uint8Array']
433433
);
434434
}
435435

@@ -448,7 +448,7 @@ Buffer.isEncoding = function isEncoding(encoding) {
448448
Buffer[kIsEncodingSymbol] = Buffer.isEncoding;
449449

450450
const kConcatErr = new errors.TypeError(
451-
'ERR_INVALID_ARG_TYPE', 'list', ['array', 'buffer', 'uint8Array']
451+
'ERR_INVALID_ARG_TYPE', 'list', ['Array', 'Buffer', 'Uint8Array']
452452
);
453453

454454
Buffer.concat = function concat(list, length) {
@@ -509,7 +509,7 @@ function byteLength(string, encoding) {
509509

510510
throw new errors.TypeError(
511511
'ERR_INVALID_ARG_TYPE', 'string',
512-
['string', 'buffer', 'arrayBuffer'], string
512+
['string', 'Buffer', 'ArrayBuffer'], string
513513
);
514514
}
515515

@@ -671,7 +671,7 @@ Buffer.prototype.equals = function equals(b) {
671671
if (!isUint8Array(b)) {
672672
throw new errors.TypeError(
673673
'ERR_INVALID_ARG_TYPE', 'otherBuffer',
674-
['buffer', 'uint8Array'], b
674+
['Buffer', 'Uint8Array'], b
675675
);
676676
}
677677
if (this === b)
@@ -700,7 +700,7 @@ Buffer.prototype.compare = function compare(target,
700700
if (!isUint8Array(target)) {
701701
throw new errors.TypeError(
702702
'ERR_INVALID_ARG_TYPE', 'target',
703-
['buffer', 'uint8Array'], target
703+
['Buffer', 'Uint8Array'], target
704704
);
705705
}
706706
if (arguments.length === 1)
@@ -783,7 +783,7 @@ function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
783783

784784
throw new errors.TypeError(
785785
'ERR_INVALID_ARG_TYPE', 'value',
786-
['string', 'buffer', 'uint8Array'], val
786+
['string', 'Buffer', 'Uint8Array'], val
787787
);
788788
}
789789

lib/dgram.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function newHandle(type, lookup) {
6363
if (lookup === undefined)
6464
lookup = dns.lookup;
6565
else if (typeof lookup !== 'function')
66-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'lookup', 'function');
66+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'lookup', 'Function');
6767

6868
if (type === 'udp4') {
6969
const handle = new UDP();

lib/dns.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function lookup(hostname, options, callback) {
133133
// Parse arguments
134134
if (hostname && typeof hostname !== 'string') {
135135
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'hostname',
136-
['string', 'falsey'], hostname);
136+
['string', 'falsy'], hostname);
137137
} else if (typeof options === 'function') {
138138
callback = options;
139139
family = 0;

lib/events.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ function _addListener(target, type, listener, prepend) {
243243

244244
if (typeof listener !== 'function') {
245245
const errors = lazyErrors();
246-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener', 'function');
246+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener', 'Function');
247247
}
248248

249249
events = target._events;
@@ -344,7 +344,7 @@ function _onceWrap(target, type, listener) {
344344
EventEmitter.prototype.once = function once(type, listener) {
345345
if (typeof listener !== 'function') {
346346
const errors = lazyErrors();
347-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener', 'function');
347+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener', 'Function');
348348
}
349349
this.on(type, _onceWrap(this, type, listener));
350350
return this;
@@ -355,7 +355,7 @@ EventEmitter.prototype.prependOnceListener =
355355
if (typeof listener !== 'function') {
356356
const errors = lazyErrors();
357357
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener',
358-
'function');
358+
'Function');
359359
}
360360
this.prependListener(type, _onceWrap(this, type, listener));
361361
return this;
@@ -369,7 +369,7 @@ EventEmitter.prototype.removeListener =
369369
if (typeof listener !== 'function') {
370370
const errors = lazyErrors();
371371
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener',
372-
'function');
372+
'Function');
373373
}
374374

375375
events = this._events;

lib/fs.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function getOptions(options, defaultOptions) {
8686
} else if (typeof options !== 'object') {
8787
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
8888
'options',
89-
['string', 'object'],
89+
['string', 'Object'],
9090
options);
9191
}
9292

@@ -1209,7 +1209,7 @@ function toUnixTimestamp(time) {
12091209
}
12101210
throw new errors.Error('ERR_INVALID_ARG_TYPE',
12111211
'time',
1212-
['Date', 'time in seconds'],
1212+
['Date', 'Time in seconds'],
12131213
time);
12141214
}
12151215

@@ -1513,7 +1513,7 @@ fs.watchFile = function(filename, options, listener) {
15131513
if (typeof listener !== 'function') {
15141514
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
15151515
'listener',
1516-
'function',
1516+
'Function',
15171517
listener);
15181518
}
15191519

@@ -1922,7 +1922,7 @@ fs.copyFile = function(src, dest, flags, callback) {
19221922
callback = flags;
19231923
flags = 0;
19241924
} else if (typeof callback !== 'function') {
1925-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'callback', 'function');
1925+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'callback', 'Function');
19261926
}
19271927

19281928
src = getPathFromURL(src);

lib/inspector.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Session extends EventEmitter {
5656
}
5757
if (params && typeof params !== 'object') {
5858
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
59-
'params', 'object', params);
59+
'params', 'Object', params);
6060
}
6161
if (callback && typeof callback !== 'function') {
6262
throw new errors.TypeError('ERR_INVALID_CALLBACK');

lib/internal/child_process.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ ChildProcess.prototype.spawn = function(options) {
273273
var i;
274274

275275
if (options === null || typeof options !== 'object') {
276-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object',
276+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object',
277277
options);
278278
}
279279

@@ -594,7 +594,7 @@ function setupChannel(target, channel) {
594594
options = undefined;
595595
} else if (options !== undefined &&
596596
(options === null || typeof options !== 'object')) {
597-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object',
597+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object',
598598
options);
599599
}
600600

lib/internal/encoding.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ function makeTextDecoderICU() {
345345
constructor(encoding = 'utf-8', options = {}) {
346346
encoding = `${encoding}`;
347347
if (typeof options !== 'object')
348-
throw new errors.Error('ERR_INVALID_ARG_TYPE', 'options', 'object');
348+
throw new errors.Error('ERR_INVALID_ARG_TYPE', 'options', 'Object');
349349

350350
const enc = getEncodingFromLabel(encoding);
351351
if (enc === undefined)
@@ -378,7 +378,7 @@ function makeTextDecoderICU() {
378378
['ArrayBuffer', 'ArrayBufferView']);
379379
}
380380
if (typeof options !== 'object') {
381-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object');
381+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
382382
}
383383

384384
var flags = 0;
@@ -417,7 +417,7 @@ function makeTextDecoderJS() {
417417
constructor(encoding = 'utf-8', options = {}) {
418418
encoding = `${encoding}`;
419419
if (typeof options !== 'object')
420-
throw new errors.Error('ERR_INVALID_ARG_TYPE', 'options', 'object');
420+
throw new errors.Error('ERR_INVALID_ARG_TYPE', 'options', 'Object');
421421

422422
const enc = getEncodingFromLabel(encoding);
423423
if (enc === undefined || !hasConverter(enc))
@@ -452,7 +452,7 @@ function makeTextDecoderJS() {
452452
['ArrayBuffer', 'ArrayBufferView']);
453453
}
454454
if (typeof options !== 'object') {
455-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object');
455+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
456456
}
457457

458458
if (this[kFlags] & CONVERTER_FLAGS_FLUSH) {

lib/internal/errors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function makeNodeError(Base) {
6161
class AssertionError extends Error {
6262
constructor(options) {
6363
if (typeof options !== 'object' || options === null) {
64-
throw new exports.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object');
64+
throw new exports.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
6565
}
6666
var { actual, expected, message, operator, stackStartFunction } = options;
6767
if (message) {

lib/internal/http2/core.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2484,7 +2484,7 @@ function connect(authority, options, listener) {
24842484
if (typeof authority === 'string')
24852485
authority = new URL(authority);
24862486

2487-
assertIsObject(authority, 'authority', ['string', 'object', 'URL']);
2487+
assertIsObject(authority, 'authority', ['string', 'Object', 'URL']);
24882488

24892489
debug(`connecting to ${authority}`);
24902490

@@ -2539,7 +2539,7 @@ function createSecureServer(options, handler) {
25392539
if (options == null || typeof options !== 'object') {
25402540
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
25412541
'options',
2542-
'object');
2542+
'Object');
25432543
}
25442544
debug('creating http2secureserver');
25452545
return new Http2SecureServer(options, handler);

lib/internal/http2/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ class NghttpError extends Error {
465465
}
466466
}
467467

468-
function assertIsObject(value, name, types = 'object') {
468+
function assertIsObject(value, name, types = 'Object') {
469469
if (value !== undefined &&
470470
(value === null ||
471471
typeof value !== 'object' ||

lib/internal/process.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ function setup_cpuUsage() {
2828
if (prevValue) {
2929
if (!previousValueIsValid(prevValue.user)) {
3030
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
31-
'preValue.user', 'Number');
31+
'preValue.user', 'number');
3232
}
3333

3434
if (!previousValueIsValid(prevValue.system)) {
3535
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
36-
'preValue.system', 'Number');
36+
'preValue.system', 'number');
3737
}
3838
}
3939

@@ -154,7 +154,7 @@ function setupKillAndExit() {
154154

155155
// eslint-disable-next-line eqeqeq
156156
if (pid != (pid | 0)) {
157-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pid', 'Number');
157+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pid', 'number');
158158
}
159159

160160
// preserve null signal

lib/internal/url.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ Object.defineProperties(URL.prototype, {
372372
// eslint-disable-next-line func-name-matching
373373
value: function format(options) {
374374
if (options && typeof options !== 'object')
375-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object');
375+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object');
376376
options = util._extend({
377377
fragment: true,
378378
unicode: false,

lib/internal/util.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ const kCustomPromisifyArgsSymbol = Symbol('customPromisifyArgs');
203203

204204
function promisify(original) {
205205
if (typeof original !== 'function')
206-
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'original', 'function');
206+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'original', 'Function');
207207

208208
if (original[kCustomPromisifiedSymbol]) {
209209
const fn = original[kCustomPromisifiedSymbol];
210210
if (typeof fn !== 'function') {
211211
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
212212
'util.promisify.custom',
213-
'function',
213+
'Function',
214214
fn);
215215
}
216216
Object.defineProperty(fn, kCustomPromisifiedSymbol, {

lib/net.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ function lookupAndConnect(self, options) {
10801080
if (options.lookup && typeof options.lookup !== 'function')
10811081
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
10821082
'options.lookup',
1083-
'function',
1083+
'Function',
10841084
options.lookup);
10851085

10861086
var dnsopts = {
@@ -1225,7 +1225,7 @@ function Server(options, connectionListener) {
12251225
} else {
12261226
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
12271227
'options',
1228-
'object',
1228+
'Object',
12291229
options);
12301230
}
12311231

lib/repl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ REPLServer.prototype.defineCommand = function(keyword, cmd) {
11081108
} else if (typeof cmd.action !== 'function') {
11091109
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
11101110
'action',
1111-
'function',
1111+
'Function',
11121112
cmd.action);
11131113
}
11141114
this.commands[keyword] = cmd;

lib/url.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ function urlFormat(urlObject, options) {
556556
urlObject = urlParse(urlObject);
557557
} else if (typeof urlObject !== 'object' || urlObject === null) {
558558
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'urlObject',
559-
['object', 'string'], urlObject);
559+
['Object', 'string'], urlObject);
560560
} else if (!(urlObject instanceof Url)) {
561561
var format = urlObject[formatSymbol];
562562
return format ?

0 commit comments

Comments
 (0)