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 <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 8 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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');

0 commit comments

Comments
 (0)