lib: Consistent error messages in all modules

This commit fixes some error messages that are not consistent with
some general rules which most of the error messages follow.

PR-URL: https://github.com/nodejs/node/pull/3374
Reviewed-By: Roman Reiss <me@silverwind.io>
This commit is contained in:
micnic 2015-10-15 00:10:25 +03:00 committed by Roman Reiss
parent af46112828
commit 20285ad177
25 changed files with 110 additions and 106 deletions

View File

@ -51,10 +51,10 @@ function ClientRequest(options, cb) {
// well, and b) possibly too restrictive for real-world usage. That's // well, and b) possibly too restrictive for real-world usage. That's
// why it only scans for spaces because those are guaranteed to create // why it only scans for spaces because those are guaranteed to create
// an invalid request. // an invalid request.
throw new TypeError('Request path contains unescaped characters.'); throw new TypeError('Request path contains unescaped characters');
} else if (protocol !== expectedProtocol) { } else if (protocol !== expectedProtocol) {
throw new Error('Protocol "' + protocol + '" not supported. ' + throw new Error('Protocol "' + protocol + '" not supported. ' +
'Expected "' + expectedProtocol + '".'); 'Expected "' + expectedProtocol + '"');
} }
const defaultPort = options.defaultPort || const defaultPort = options.defaultPort ||

View File

@ -337,11 +337,11 @@ OutgoingMessage.prototype.setHeader = function(name, value) {
throw new TypeError( throw new TypeError(
'Header name must be a valid HTTP Token ["' + name + '"]'); 'Header name must be a valid HTTP Token ["' + name + '"]');
if (typeof name !== 'string') if (typeof name !== 'string')
throw new TypeError('`name` should be a string in setHeader(name, value).'); throw new TypeError('"name" should be a string in setHeader(name, value)');
if (value === undefined) if (value === undefined)
throw new Error('`value` required in setHeader("' + name + '", value).'); throw new Error('"value" required in setHeader("' + name + '", value)');
if (this._header) if (this._header)
throw new Error('Can\'t set headers after they are sent.'); throw new Error('Can\'t set headers after they are sent');
if (this._headers === null) if (this._headers === null)
this._headers = {}; this._headers = {};
@ -357,7 +357,7 @@ OutgoingMessage.prototype.setHeader = function(name, value) {
OutgoingMessage.prototype.getHeader = function(name) { OutgoingMessage.prototype.getHeader = function(name) {
if (arguments.length < 1) { if (arguments.length < 1) {
throw new Error('`name` is required for getHeader(name).'); throw new Error('"name" argument is required for getHeader(name)');
} }
if (!this._headers) return; if (!this._headers) return;
@ -369,11 +369,11 @@ OutgoingMessage.prototype.getHeader = function(name) {
OutgoingMessage.prototype.removeHeader = function(name) { OutgoingMessage.prototype.removeHeader = function(name) {
if (arguments.length < 1) { if (arguments.length < 1) {
throw new Error('`name` is required for removeHeader(name).'); throw new Error('"name" argument is required for removeHeader(name)');
} }
if (this._header) { if (this._header) {
throw new Error('Can\'t remove headers after they are sent.'); throw new Error('Can\'t remove headers after they are sent');
} }
var key = name.toLowerCase(); var key = name.toLowerCase();
@ -392,7 +392,7 @@ OutgoingMessage.prototype.removeHeader = function(name) {
OutgoingMessage.prototype._renderHeaders = function() { OutgoingMessage.prototype._renderHeaders = function() {
if (this._header) { if (this._header) {
throw new Error('Can\'t render headers after they are sent to the client.'); throw new Error('Can\'t render headers after they are sent to the client');
} }
var headersMap = this._headers; var headersMap = this._headers;
@ -436,7 +436,7 @@ OutgoingMessage.prototype.write = function(chunk, encoding, callback) {
} }
if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) { if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
throw new TypeError('first argument must be a string or Buffer'); throw new TypeError('First argument must be a string or Buffer');
} }
@ -533,7 +533,7 @@ OutgoingMessage.prototype.end = function(data, encoding, callback) {
} }
if (data && typeof data !== 'string' && !(data instanceof Buffer)) { if (data && typeof data !== 'string' && !(data instanceof Buffer)) {
throw new TypeError('first argument must be a string or Buffer'); throw new TypeError('First argument must be a string or Buffer');
} }
if (this.finished) { if (this.finished) {

View File

@ -889,7 +889,7 @@ function endReadable(stream) {
// If we get here before consuming all the bytes, then that is a // If we get here before consuming all the bytes, then that is a
// bug in node. Should never happen. // bug in node. Should never happen.
if (state.length > 0) if (state.length > 0)
throw new Error('endReadable called on non-empty stream'); throw new Error('"endReadable()" called on non-empty stream');
if (!state.endEmitted) { if (!state.endEmitted) {
state.ended = true; state.ended = true;

View File

@ -139,7 +139,7 @@ Transform.prototype.push = function(chunk, encoding) {
// an error, then that'll put the hurt on the whole operation. If you // an error, then that'll put the hurt on the whole operation. If you
// never call cb(), then you'll never get another chunk. // never call cb(), then you'll never get another chunk.
Transform.prototype._transform = function(chunk, encoding, cb) { Transform.prototype._transform = function(chunk, encoding, cb) {
throw new Error('not implemented'); throw new Error('Not implemented');
}; };
Transform.prototype._write = function(chunk, encoding, cb) { Transform.prototype._write = function(chunk, encoding, cb) {
@ -183,10 +183,10 @@ function done(stream, er) {
var ts = stream._transformState; var ts = stream._transformState;
if (ws.length) if (ws.length)
throw new Error('calling transform done when ws.length != 0'); throw new Error('Calling transform done when ws.length != 0');
if (ts.transforming) if (ts.transforming)
throw new Error('calling transform done when still transforming'); throw new Error('Calling transform done when still transforming');
return stream.push(null); return stream.push(null);
} }

View File

@ -151,7 +151,7 @@ function Writable(options) {
// Otherwise people can pipe Writable streams, which is just wrong. // Otherwise people can pipe Writable streams, which is just wrong.
Writable.prototype.pipe = function() { Writable.prototype.pipe = function() {
this.emit('error', new Error('Cannot pipe. Not readable.')); this.emit('error', new Error('Cannot pipe, not readable'));
}; };

View File

@ -13,7 +13,7 @@ var Connection = null;
try { try {
Connection = process.binding('crypto').Connection; Connection = process.binding('crypto').Connection;
} catch (e) { } catch (e) {
throw new Error('node.js not compiled with openssl crypto support.'); throw new Error('Node.js is not compiled with openssl crypto support');
} }
function SlabBuffer() { function SlabBuffer() {
@ -590,7 +590,7 @@ function onhandshakestart() {
// state machine and OpenSSL is not re-entrant. We cannot allow the user's // state machine and OpenSSL is not re-entrant. We cannot allow the user's
// callback to destroy the connection right now, it would crash and burn. // callback to destroy the connection right now, it would crash and burn.
setImmediate(function() { setImmediate(function() {
var err = new Error('TLS session renegotiation attack detected.'); var err = new Error('TLS session renegotiation attack detected');
if (self.cleartext) self.cleartext.emit('error', err); if (self.cleartext) self.cleartext.emit('error', err);
}); });
} }

View File

@ -37,7 +37,7 @@ function onhandshakestart() {
// state machine and OpenSSL is not re-entrant. We cannot allow the user's // state machine and OpenSSL is not re-entrant. We cannot allow the user's
// callback to destroy the connection right now, it would crash and burn. // callback to destroy the connection right now, it would crash and burn.
setImmediate(function() { setImmediate(function() {
var err = new Error('TLS session renegotiation attack detected.'); var err = new Error('TLS session renegotiation attack detected');
self._emitTLSError(err); self._emitTLSError(err);
}); });
} }
@ -756,7 +756,7 @@ function Server(/* [options], listener */) {
var timeout = options.handshakeTimeout || (120 * 1000); var timeout = options.handshakeTimeout || (120 * 1000);
if (typeof timeout !== 'number') { if (typeof timeout !== 'number') {
throw new TypeError('handshakeTimeout must be a number'); throw new TypeError('"handshakeTimeout" option must be a number');
} }
if (self.sessionTimeout) { if (self.sessionTimeout) {
@ -902,7 +902,7 @@ Server.prototype.setOptions = function(options) {
// SNI Contexts High-Level API // SNI Contexts High-Level API
Server.prototype.addContext = function(servername, context) { Server.prototype.addContext = function(servername, context) {
if (!servername) { if (!servername) {
throw new Error('Servername is required parameter for Server.addContext'); throw new Error('"servername" is required parameter for Server.addContext');
} }
var re = new RegExp('^' + var re = new RegExp('^' +

View File

@ -285,7 +285,7 @@ function _throws(shouldThrow, block, expected, message) {
var actual; var actual;
if (typeof block !== 'function') { if (typeof block !== 'function') {
throw new TypeError('block must be a function'); throw new TypeError('"block" argument must be a function');
} }
if (typeof expected === 'string') { if (typeof expected === 'string') {

View File

@ -136,7 +136,7 @@ function fromObject(obj) {
} }
if (obj == null) { if (obj == null) {
throw new TypeError('must start with number, buffer, array or string'); throw new TypeError('Must start with number, buffer, array or string');
} }
if (obj instanceof ArrayBuffer) { if (obj instanceof ArrayBuffer) {
@ -164,7 +164,7 @@ function fromObject(obj) {
return b; return b;
} }
throw new TypeError('must start with number, buffer, array or string'); throw new TypeError('Must start with number, buffer, array or string');
} }
@ -217,7 +217,7 @@ Buffer.isEncoding = function(encoding) {
Buffer.concat = function(list, length) { Buffer.concat = function(list, length) {
if (!Array.isArray(list)) if (!Array.isArray(list))
throw new TypeError('list argument must be an Array of Buffers.'); throw new TypeError('"list" argument must be an Array of Buffers');
if (list.length === 0) if (list.length === 0)
return new Buffer(0); return new Buffer(0);
@ -375,7 +375,7 @@ Buffer.prototype.toString = function() {
var result = slowToString.apply(this, arguments); var result = slowToString.apply(this, arguments);
} }
if (result === undefined) if (result === undefined)
throw new Error('toString failed'); throw new Error('"toString()" failed');
return result; return result;
}; };
@ -462,7 +462,7 @@ Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
return binding.indexOfNumber(this, val, byteOffset); return binding.indexOfNumber(this, val, byteOffset);
} }
throw new TypeError('val must be string, number or Buffer'); throw new TypeError('"val" argument must be string, number or Buffer');
}; };
@ -471,7 +471,7 @@ Buffer.prototype.fill = function fill(val, start, end) {
end = (end === undefined) ? this.length : end >> 0; end = (end === undefined) ? this.length : end >> 0;
if (start < 0 || end > this.length) if (start < 0 || end > this.length)
throw new RangeError('out of range index'); throw new RangeError('Out of range index');
if (end <= start) if (end <= start)
return this; return this;
@ -493,7 +493,7 @@ Buffer.prototype.fill = function fill(val, start, end) {
Buffer.prototype.get = internalUtil.deprecate(function get(offset) { Buffer.prototype.get = internalUtil.deprecate(function get(offset) {
offset = ~~offset; offset = ~~offset;
if (offset < 0 || offset >= this.length) if (offset < 0 || offset >= this.length)
throw new RangeError('index out of range'); throw new RangeError('Index out of range');
return this[offset]; return this[offset];
}, 'Buffer.get is deprecated. Use array indexes instead.'); }, 'Buffer.get is deprecated. Use array indexes instead.');
@ -502,7 +502,7 @@ Buffer.prototype.get = internalUtil.deprecate(function get(offset) {
Buffer.prototype.set = internalUtil.deprecate(function set(offset, v) { Buffer.prototype.set = internalUtil.deprecate(function set(offset, v) {
offset = ~~offset; offset = ~~offset;
if (offset < 0 || offset >= this.length) if (offset < 0 || offset >= this.length)
throw new RangeError('index out of range'); throw new RangeError('Index out of range');
return this[offset] = v; return this[offset] = v;
}, 'Buffer.set is deprecated. Use array indexes instead.'); }, 'Buffer.set is deprecated. Use array indexes instead.');
@ -552,7 +552,7 @@ Buffer.prototype.write = function(string, offset, length, encoding) {
length = remaining; length = remaining;
if (string.length > 0 && (length < 0 || offset < 0)) if (string.length > 0 && (length < 0 || offset < 0))
throw new RangeError('attempt to write outside buffer bounds'); throw new RangeError('Attempt to write outside buffer bounds');
if (!encoding) if (!encoding)
encoding = 'utf8'; encoding = 'utf8';
@ -612,7 +612,7 @@ Buffer.prototype.slice = function slice(start, end) {
function checkOffset(offset, ext, length) { function checkOffset(offset, ext, length) {
if (offset + ext > length) if (offset + ext > length)
throw new RangeError('index out of range'); throw new RangeError('Index out of range');
} }
@ -820,11 +820,11 @@ Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
function checkInt(buffer, value, offset, ext, max, min) { function checkInt(buffer, value, offset, ext, max, min) {
if (!(buffer instanceof Buffer)) if (!(buffer instanceof Buffer))
throw new TypeError('buffer must be a Buffer instance'); throw new TypeError('"buffer" argument must be a Buffer instance');
if (value > max || value < min) if (value > max || value < min)
throw new TypeError('value is out of bounds'); throw new TypeError('"value" argument is out of bounds');
if (offset + ext > buffer.length) if (offset + ext > buffer.length)
throw new RangeError('index out of range'); throw new RangeError('Index out of range');
} }
@ -1030,9 +1030,9 @@ Buffer.prototype.writeInt32BE = function(value, offset, noAssert) {
function checkFloat(buffer, value, offset, ext) { function checkFloat(buffer, value, offset, ext) {
if (!(buffer instanceof Buffer)) if (!(buffer instanceof Buffer))
throw new TypeError('buffer must be a Buffer instance'); throw new TypeError('"buffer" argument must be a Buffer instance');
if (offset + ext > buffer.length) if (offset + ext > buffer.length)
throw new RangeError('index out of range'); throw new RangeError('Index out of range');
} }

View File

@ -251,7 +251,7 @@ exports.execFile = function(file /*, args, options, callback*/) {
stdoutLen += chunk.length; stdoutLen += chunk.length;
if (stdoutLen > options.maxBuffer) { if (stdoutLen > options.maxBuffer) {
ex = new Error('stdout maxBuffer exceeded.'); ex = new Error('stdout maxBuffer exceeded');
kill(); kill();
} else { } else {
if (!encoding) if (!encoding)
@ -265,7 +265,7 @@ exports.execFile = function(file /*, args, options, callback*/) {
stderrLen += chunk.length; stderrLen += chunk.length;
if (stderrLen > options.maxBuffer) { if (stderrLen > options.maxBuffer) {
ex = new Error('stderr maxBuffer exceeded.'); ex = new Error('stderr maxBuffer exceeded');
kill(); kill();
} else { } else {
if (!encoding) if (!encoding)
@ -316,7 +316,7 @@ function normalizeSpawnArguments(file /*, args, options*/) {
if (options === undefined) if (options === undefined)
options = {}; options = {};
else if (options === null || typeof options !== 'object') else if (options === null || typeof options !== 'object')
throw new TypeError('options argument must be an object'); throw new TypeError('"options" argument must be an object');
options = util._extend({}, options); options = util._extend({}, options);
args.unshift(file); args.unshift(file);

View File

@ -12,7 +12,7 @@ try {
var getHashes = binding.getHashes; var getHashes = binding.getHashes;
var getCurves = binding.getCurves; var getCurves = binding.getCurves;
} catch (e) { } catch (e) {
throw new Error('node.js not compiled with openssl crypto support.'); throw new Error('Node.js is not compiled with openssl crypto support');
} }
const Buffer = require('buffer').Buffer; const Buffer = require('buffer').Buffer;
@ -486,7 +486,7 @@ DiffieHellman.prototype.setPrivateKey = function(key, encoding) {
function ECDH(curve) { function ECDH(curve) {
if (typeof curve !== 'string') if (typeof curve !== 'string')
throw new TypeError('curve should be a string'); throw new TypeError('"curve" argument should be a string');
this._handle = new binding.ECDH(curve); this._handle = new binding.ECDH(curve);
} }
@ -604,10 +604,10 @@ Certificate.prototype.exportChallenge = function(object, encoding) {
exports.setEngine = function setEngine(id, flags) { exports.setEngine = function setEngine(id, flags) {
if (typeof id !== 'string') if (typeof id !== 'string')
throw new TypeError('id should be a string'); throw new TypeError('"id" argument should be a string');
if (flags && typeof flags !== 'number') if (flags && typeof flags !== 'number')
throw new TypeError('flags should be a number, if present'); throw new TypeError('"flags" argument should be a number, if present');
flags = flags >>> 0; flags = flags >>> 0;
// Use provided engine for everything by default // Use provided engine for everything by default

View File

@ -54,7 +54,7 @@ function newHandle(type) {
} }
if (type == 'unix_dgram') if (type == 'unix_dgram')
throw new Error('unix_dgram sockets are not supported any more.'); throw new Error('"unix_dgram" type sockets are not supported any more');
throw new Error('Bad socket type specified. Valid types are: udp4, udp6'); throw new Error('Bad socket type specified. Valid types are: udp4, udp6');
} }
@ -233,7 +233,7 @@ Socket.prototype.sendto = function(buffer,
address, address,
callback) { callback) {
if (typeof offset !== 'number' || typeof length !== 'number') if (typeof offset !== 'number' || typeof length !== 'number')
throw new Error('send takes offset and length as args 2 and 3'); throw new Error('Send takes "offset" and "length" as args 2 and 3');
if (typeof address !== 'string') if (typeof address !== 'string')
throw new Error(this.type + ' sockets must send to port, address'); throw new Error(this.type + ' sockets must send to port, address');
@ -254,7 +254,7 @@ Socket.prototype.send = function(buffer,
buffer = new Buffer(buffer); buffer = new Buffer(buffer);
if (!(buffer instanceof Buffer)) if (!(buffer instanceof Buffer))
throw new TypeError('First argument must be a buffer or string.'); throw new TypeError('First argument must be a buffer or string');
offset = offset | 0; offset = offset | 0;
if (offset < 0) if (offset < 0)
@ -262,7 +262,7 @@ Socket.prototype.send = function(buffer,
if ((length == 0 && offset > buffer.length) || if ((length == 0 && offset > buffer.length) ||
(length > 0 && offset >= buffer.length)) (length > 0 && offset >= buffer.length))
throw new RangeError('Offset into buffer too large'); throw new RangeError('Offset into buffer is too large');
// Sending a zero-length datagram is kind of pointless but it _is_ // Sending a zero-length datagram is kind of pointless but it _is_
// allowed, hence check that length >= 0 rather than > 0. // allowed, hence check that length >= 0 rather than > 0.

View File

@ -110,13 +110,13 @@ exports.lookup = function lookup(hostname, options, callback) {
// Parse arguments // Parse arguments
if (hostname && typeof hostname !== 'string') { if (hostname && typeof hostname !== 'string') {
throw new TypeError('invalid arguments: ' + throw new TypeError('Invalid arguments: ' +
'hostname must be a string or falsey'); 'hostname must be a string or falsey');
} else if (typeof options === 'function') { } else if (typeof options === 'function') {
callback = options; callback = options;
family = 0; family = 0;
} else if (typeof callback !== 'function') { } else if (typeof callback !== 'function') {
throw new TypeError('invalid arguments: callback must be passed'); throw new TypeError('Invalid arguments: callback must be passed');
} else if (options !== null && typeof options === 'object') { } else if (options !== null && typeof options === 'object') {
hints = options.hints >>> 0; hints = options.hints >>> 0;
family = options.family >>> 0; family = options.family >>> 0;
@ -126,14 +126,14 @@ exports.lookup = function lookup(hostname, options, callback) {
hints !== exports.ADDRCONFIG && hints !== exports.ADDRCONFIG &&
hints !== exports.V4MAPPED && hints !== exports.V4MAPPED &&
hints !== (exports.ADDRCONFIG | exports.V4MAPPED)) { hints !== (exports.ADDRCONFIG | exports.V4MAPPED)) {
throw new TypeError('invalid argument: hints must use valid flags'); throw new TypeError('Invalid argument: hints must use valid flags');
} }
} else { } else {
family = options >>> 0; family = options >>> 0;
} }
if (family !== 0 && family !== 4 && family !== 6) if (family !== 0 && family !== 4 && family !== 6)
throw new TypeError('invalid argument: family must be 4 or 6'); throw new TypeError('Invalid argument: family must be 4 or 6');
callback = makeAsync(callback); callback = makeAsync(callback);
@ -184,10 +184,10 @@ function onlookupservice(err, host, service) {
// lookupService(address, port, callback) // lookupService(address, port, callback)
exports.lookupService = function(host, port, callback) { exports.lookupService = function(host, port, callback) {
if (arguments.length !== 3) if (arguments.length !== 3)
throw new Error('invalid arguments'); throw new Error('Invalid arguments');
if (cares.isIP(host) === 0) if (cares.isIP(host) === 0)
throw new TypeError('host needs to be a valid IP address'); throw new TypeError('"host" argument needs to be a valid IP address');
callback = makeAsync(callback); callback = makeAsync(callback);
@ -218,9 +218,9 @@ function resolver(bindingName) {
return function query(name, callback) { return function query(name, callback) {
if (typeof name !== 'string') { if (typeof name !== 'string') {
throw new Error('Name must be a string'); throw new Error('"name" argument must be a string');
} else if (typeof callback !== 'function') { } else if (typeof callback !== 'function') {
throw new Error('Callback must be a function'); throw new Error('"callback" argument must be a function');
} }
callback = makeAsync(callback); callback = makeAsync(callback);
@ -259,7 +259,7 @@ exports.resolve = function(hostname, type_, callback_) {
resolver = exports.resolve4; resolver = exports.resolve4;
callback = type_; callback = type_;
} else { } else {
throw new Error('Type must be a string'); throw new Error('"type" argument must be a string');
} }
if (typeof resolver === 'function') { if (typeof resolver === 'function') {

View File

@ -42,7 +42,7 @@ EventEmitter.init = function() {
// that to be increased. Set to zero for unlimited. // that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) { EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
if (typeof n !== 'number' || n < 0 || isNaN(n)) if (typeof n !== 'number' || n < 0 || isNaN(n))
throw new TypeError('n must be a positive number'); throw new TypeError('"n" argument must be a positive number');
this._maxListeners = n; this._maxListeners = n;
return this; return this;
}; };
@ -132,7 +132,7 @@ EventEmitter.prototype.emit = function emit(type) {
er = arguments[1]; er = arguments[1];
if (domain) { if (domain) {
if (!er) if (!er)
er = new Error('Uncaught, unspecified "error" event.'); er = new Error('Uncaught, unspecified "error" event');
er.domainEmitter = this; er.domainEmitter = this;
er.domain = domain; er.domain = domain;
er.domainThrown = false; er.domainThrown = false;
@ -194,7 +194,7 @@ EventEmitter.prototype.addListener = function addListener(type, listener) {
var existing; var existing;
if (typeof listener !== 'function') if (typeof listener !== 'function')
throw new TypeError('listener must be a function'); throw new TypeError('"listener" argument must be a function');
events = this._events; events = this._events;
if (!events) { if (!events) {
@ -248,7 +248,7 @@ EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.once = function once(type, listener) { EventEmitter.prototype.once = function once(type, listener) {
if (typeof listener !== 'function') if (typeof listener !== 'function')
throw new TypeError('listener must be a function'); throw new TypeError('"listener" argument must be a function');
var fired = false; var fired = false;
@ -273,7 +273,7 @@ EventEmitter.prototype.removeListener =
var list, events, position, i; var list, events, position, i;
if (typeof listener !== 'function') if (typeof listener !== 'function')
throw new TypeError('listener must be a function'); throw new TypeError('"listener" argument must be a function');
events = this._events; events = this._events;
if (!events) if (!events)

View File

@ -75,7 +75,7 @@ function makeCallback(cb) {
} }
if (typeof cb !== 'function') { if (typeof cb !== 'function') {
throw new TypeError('callback must be a function'); throw new TypeError('"callback" argument must be a function');
} }
return function() { return function() {
@ -91,7 +91,7 @@ function assertEncoding(encoding) {
function nullCheck(path, callback) { function nullCheck(path, callback) {
if (('' + path).indexOf('\u0000') !== -1) { if (('' + path).indexOf('\u0000') !== -1) {
var er = new Error('Path must be a string without null bytes.'); var er = new Error('Path must be a string without null bytes');
er.code = 'ENOENT'; er.code = 'ENOENT';
if (typeof callback !== 'function') if (typeof callback !== 'function')
throw er; throw er;
@ -184,7 +184,7 @@ fs.access = function(path, mode, callback) {
callback = mode; callback = mode;
mode = fs.F_OK; mode = fs.F_OK;
} else if (typeof callback !== 'function') { } else if (typeof callback !== 'function') {
throw new TypeError('callback must be a function'); throw new TypeError('"callback" argument must be a function');
} }
if (!nullCheck(path, callback)) if (!nullCheck(path, callback))
@ -1410,7 +1410,7 @@ fs.watchFile = function(filename, options, listener) {
} }
if (typeof listener !== 'function') { if (typeof listener !== 'function') {
throw new Error('watchFile requires a listener function'); throw new Error('"watchFile()" requires a listener function');
} }
stat = statWatchers.get(filename); stat = statWatchers.get(filename);
@ -1703,7 +1703,7 @@ function ReadStream(path, options) {
else if (typeof options === 'string') else if (typeof options === 'string')
options = { encoding: options }; options = { encoding: options };
else if (options === null || typeof options !== 'object') else if (options === null || typeof options !== 'object')
throw new TypeError('options must be a string or an object'); throw new TypeError('"options" argument must be a string or an object');
// a little bit bigger buffer and water marks by default // a little bit bigger buffer and water marks by default
options = Object.create(options); options = Object.create(options);
@ -1724,16 +1724,16 @@ function ReadStream(path, options) {
if (this.start !== undefined) { if (this.start !== undefined) {
if (typeof this.start !== 'number') { if (typeof this.start !== 'number') {
throw new TypeError('start must be a Number'); throw new TypeError('"start" option must be a Number');
} }
if (this.end === undefined) { if (this.end === undefined) {
this.end = Infinity; this.end = Infinity;
} else if (typeof this.end !== 'number') { } else if (typeof this.end !== 'number') {
throw new TypeError('end must be a Number'); throw new TypeError('"end" option must be a Number');
} }
if (this.start > this.end) { if (this.start > this.end) {
throw new Error('start must be <= end'); throw new Error('"start" option must be <= "end" option');
} }
this.pos = this.start; this.pos = this.start;
@ -1874,7 +1874,7 @@ function WriteStream(path, options) {
else if (typeof options === 'string') else if (typeof options === 'string')
options = { encoding: options }; options = { encoding: options };
else if (options === null || typeof options !== 'object') else if (options === null || typeof options !== 'object')
throw new TypeError('options must be a string or an object'); throw new TypeError('"options" argument must be a string or an object');
options = Object.create(options); options = Object.create(options);
@ -1891,10 +1891,10 @@ function WriteStream(path, options) {
if (this.start !== undefined) { if (this.start !== undefined) {
if (typeof this.start !== 'number') { if (typeof this.start !== 'number') {
throw new TypeError('start must be a Number'); throw new TypeError('"start" option must be a Number');
} }
if (this.start < 0) { if (this.start < 0) {
throw new Error('start must be >= zero'); throw new Error('"start" must be >= zero');
} }
this.pos = this.start; this.pos = this.start;
@ -2036,7 +2036,7 @@ SyncWriteStream.prototype.write = function(data, arg1, arg2) {
} else if (typeof arg1 === 'function') { } else if (typeof arg1 === 'function') {
cb = arg1; cb = arg1;
} else { } else {
throw new Error('bad arg'); throw new Error('Bad arguments');
} }
} }
assertEncoding(encoding); assertEncoding(encoding);

View File

@ -519,7 +519,7 @@ function setupChannel(target, channel) {
assert(this.connected || this._channel); assert(this.connected || this._channel);
if (message === undefined) if (message === undefined)
throw new TypeError('message cannot be undefined'); throw new TypeError('"message" argument cannot be undefined');
// package messages with a handle object // package messages with a handle object
if (handle) { if (handle) {
@ -541,7 +541,7 @@ function setupChannel(target, channel) {
} else if (handle instanceof UDP) { } else if (handle instanceof UDP) {
message.type = 'dgram.Native'; message.type = 'dgram.Native';
} else { } else {
throw new TypeError("This handle type can't be sent"); throw new TypeError('This handle type can\'t be sent');
} }
// Queue-up message and handle if we haven't received ACK yet. // Queue-up message and handle if we haven't received ACK yet.

View File

@ -614,7 +614,7 @@ Socket.prototype.__defineGetter__('localPort', function() {
Socket.prototype.write = function(chunk, encoding, cb) { Socket.prototype.write = function(chunk, encoding, cb) {
if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) if (typeof chunk !== 'string' && !(chunk instanceof Buffer))
throw new TypeError('invalid data'); throw new TypeError('Invalid data');
return stream.Duplex.prototype.write.apply(this, arguments); return stream.Duplex.prototype.write.apply(this, arguments);
}; };
@ -637,7 +637,7 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
this._unrefTimer(); this._unrefTimer();
if (!this._handle) { if (!this._handle) {
this._destroy(new Error('This socket is closed.'), cb); this._destroy(new Error('This socket is closed'), cb);
return false; return false;
} }
@ -915,16 +915,18 @@ function lookupAndConnect(self, options) {
var localPort = options.localPort; var localPort = options.localPort;
if (localAddress && !exports.isIP(localAddress)) if (localAddress && !exports.isIP(localAddress))
throw new TypeError('localAddress must be a valid IP: ' + localAddress); throw new TypeError('"localAddress" option must be a valid IP: ' +
localAddress);
if (localPort && typeof localPort !== 'number') if (localPort && typeof localPort !== 'number')
throw new TypeError('localPort should be a number: ' + localPort); throw new TypeError('"localPort" option should be a number: ' + localPort);
if (typeof port !== 'undefined') { if (typeof port !== 'undefined') {
if (typeof port !== 'number' && typeof port !== 'string') if (typeof port !== 'number' && typeof port !== 'string')
throw new TypeError('port should be a number or string: ' + port); throw new TypeError('"port" option should be a number or string: ' +
port);
if (!isLegalPort(port)) if (!isLegalPort(port))
throw new RangeError('port should be >= 0 and < 65536: ' + port); throw new RangeError('"port" option should be >= 0 and < 65536: ' + port);
} }
port |= 0; port |= 0;
@ -940,7 +942,7 @@ function lookupAndConnect(self, options) {
} }
if (options.lookup && typeof options.lookup !== 'function') if (options.lookup && typeof options.lookup !== 'function')
throw new TypeError('options.lookup should be a function.'); throw new TypeError('"lookup" option should be a function');
var dnsopts = { var dnsopts = {
family: options.family, family: options.family,
@ -1342,7 +1344,8 @@ Server.prototype.listen = function() {
// Undefined is interpreted as zero (random port) for consistency // Undefined is interpreted as zero (random port) for consistency
// with net.connect(). // with net.connect().
if (typeof h.port !== 'undefined' && !isLegalPort(h.port)) if (typeof h.port !== 'undefined' && !isLegalPort(h.port))
throw new RangeError('port should be >= 0 and < 65536: ' + h.port); throw new RangeError('"port" option should be >= 0 and < 65536: ' +
h.port);
if (h.host) if (h.host)
listenAfterLookup(h.port | 0, h.host, backlog, h.exclusive); listenAfterLookup(h.port | 0, h.host, backlog, h.exclusive);
else else

View File

@ -338,7 +338,7 @@ win32.dirname = function(path) {
win32.basename = function(path, ext) { win32.basename = function(path, ext) {
if (ext !== undefined && typeof ext !== 'string') if (ext !== undefined && typeof ext !== 'string')
throw new TypeError('ext must be a string'); throw new TypeError('"ext" argument must be a string');
var f = win32SplitPath(path)[2]; var f = win32SplitPath(path)[2];
// TODO: make this comparison case-insensitive on windows? // TODO: make this comparison case-insensitive on windows?
@ -357,7 +357,7 @@ win32.extname = function(path) {
win32.format = function(pathObject) { win32.format = function(pathObject) {
if (pathObject === null || typeof pathObject !== 'object') { if (pathObject === null || typeof pathObject !== 'object') {
throw new TypeError( throw new TypeError(
"Parameter 'pathObject' must be an object, not " + typeof pathObject 'Parameter "pathObject" must be an object, not ' + typeof pathObject
); );
} }
@ -365,7 +365,7 @@ win32.format = function(pathObject) {
if (typeof root !== 'string') { if (typeof root !== 'string') {
throw new TypeError( throw new TypeError(
"'pathObject.root' must be a string or undefined, not " + '"pathObject.root" must be a string or undefined, not ' +
typeof pathObject.root typeof pathObject.root
); );
} }
@ -547,7 +547,7 @@ posix.dirname = function(path) {
posix.basename = function(path, ext) { posix.basename = function(path, ext) {
if (ext !== undefined && typeof ext !== 'string') if (ext !== undefined && typeof ext !== 'string')
throw new TypeError('ext must be a string'); throw new TypeError('"ext" argument must be a string');
var f = posixSplitPath(path)[2]; var f = posixSplitPath(path)[2];
@ -574,7 +574,7 @@ posix.format = function(pathObject) {
if (typeof root !== 'string') { if (typeof root !== 'string') {
throw new TypeError( throw new TypeError(
"'pathObject.root' must be a string or undefined, not " + '"pathObject.root" must be a string or undefined, not ' +
typeof pathObject.root typeof pathObject.root
); );
} }

View File

@ -50,13 +50,13 @@ function Interface(input, output, completer, terminal) {
historySize = historySize || kHistorySize; historySize = historySize || kHistorySize;
if (completer && typeof completer !== 'function') { if (completer && typeof completer !== 'function') {
throw new TypeError('Argument \'completer\' must be a function'); throw new TypeError('Argument "completer" must be a function');
} }
if (typeof historySize !== 'number' || if (typeof historySize !== 'number' ||
isNaN(historySize) || isNaN(historySize) ||
historySize < 0) { historySize < 0) {
throw new TypeError('Argument \'historySize\' must be a positive number'); throw new TypeError('Argument "historySize" must be a positive number');
} }
// backwards compat; check the isTTY prop of the output stream // backwards compat; check the isTTY prop of the output stream
@ -213,7 +213,7 @@ Interface.prototype._onLine = function(line) {
Interface.prototype._writeToOutput = function _writeToOutput(stringToWrite) { Interface.prototype._writeToOutput = function _writeToOutput(stringToWrite) {
if (typeof stringToWrite !== 'string') if (typeof stringToWrite !== 'string')
throw new TypeError('stringToWrite must be a string'); throw new TypeError('"stringToWrite" argument must be a string');
if (this.output !== null && this.output !== undefined) if (this.output !== null && this.output !== undefined)
this.output.write(stringToWrite); this.output.write(stringToWrite);
@ -1270,7 +1270,7 @@ function cursorTo(stream, x, y) {
return; return;
if (typeof x !== 'number') if (typeof x !== 'number')
throw new Error("Can't set cursor row without also setting it's column"); throw new Error('Can\'t set cursor row without also setting it\'s column');
if (typeof y !== 'number') { if (typeof y !== 'number') {
stream.write('\x1b[' + (x + 1) + 'G'); stream.write('\x1b[' + (x + 1) + 'G');

View File

@ -897,7 +897,7 @@ REPLServer.prototype.defineCommand = function(keyword, cmd) {
if (typeof cmd === 'function') { if (typeof cmd === 'function') {
cmd = {action: cmd}; cmd = {action: cmd};
} else if (typeof cmd.action !== 'function') { } else if (typeof cmd.action !== 'function') {
throw new Error('bad argument, action must be a function'); throw new Error('Bad argument, "action" command must be a function');
} }
this.commands[keyword] = cmd; this.commands[keyword] = cmd;
}; };

View File

@ -149,11 +149,12 @@ const unenroll = exports.unenroll = function(item) {
// Does not start the time, just sets up the members needed. // Does not start the time, just sets up the members needed.
exports.enroll = function(item, msecs) { exports.enroll = function(item, msecs) {
if (typeof msecs !== 'number') { if (typeof msecs !== 'number') {
throw new TypeError('msecs must be a number'); throw new TypeError('"msecs" argument must be a number');
} }
if (msecs < 0 || !isFinite(msecs)) { if (msecs < 0 || !isFinite(msecs)) {
throw new RangeError('msecs must be a non-negative finite number'); throw new RangeError('"msecs" argument must be ' +
'a non-negative finite number');
} }
// if this item was already in a list somewhere // if this item was already in a list somewhere

View File

@ -17,7 +17,7 @@ exports.isatty = function(fd) {
// backwards-compat // backwards-compat
exports.setRawMode = internalUtil.deprecate(function(flag) { exports.setRawMode = internalUtil.deprecate(function(flag) {
if (!process.stdin.isTTY) { if (!process.stdin.isTTY) {
throw new Error('can\'t set raw mode on non-tty'); throw new Error('Can\'t set raw mode on non-tty');
} }
process.stdin.setRawMode(flag); process.stdin.setRawMode(flag);
}, 'tty.setRawMode is deprecated. ' + }, 'tty.setRawMode is deprecated. ' +

View File

@ -87,7 +87,7 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
if (typeof url !== 'string') { if (typeof url !== 'string') {
throw new TypeError("Parameter 'url' must be a string, not " + typeof url); throw new TypeError('Parameter "url" must be a string, not ' + typeof url);
} }
// Copy chrome, IE, opera backslash-handling behavior. // Copy chrome, IE, opera backslash-handling behavior.
@ -354,7 +354,7 @@ function urlFormat(obj) {
if (typeof obj === 'string') obj = urlParse(obj); if (typeof obj === 'string') obj = urlParse(obj);
else if (typeof obj !== 'object' || obj === null) else if (typeof obj !== 'object' || obj === null)
throw new TypeError("Parameter 'urlObj' must be an object, not " + throw new TypeError('Parameter "urlObj" must be an object, not ' +
obj === null ? 'null' : typeof obj); obj === null ? 'null' : typeof obj);
else if (!(obj instanceof Url)) return Url.prototype.format.call(obj); else if (!(obj instanceof Url)) return Url.prototype.format.call(obj);

View File

@ -745,16 +745,16 @@ exports.log = function() {
exports.inherits = function(ctor, superCtor) { exports.inherits = function(ctor, superCtor) {
if (ctor === undefined || ctor === null) if (ctor === undefined || ctor === null)
throw new TypeError('The constructor to `inherits` must not be ' + throw new TypeError('The constructor to "inherits" must not be ' +
'null or undefined.'); 'null or undefined');
if (superCtor === undefined || superCtor === null) if (superCtor === undefined || superCtor === null)
throw new TypeError('The super constructor to `inherits` must not ' + throw new TypeError('The super constructor to "inherits" must not ' +
'be null or undefined.'); 'be null or undefined');
if (superCtor.prototype === undefined) if (superCtor.prototype === undefined)
throw new TypeError('The super constructor to `inherits` must ' + throw new TypeError('The super constructor to "inherits" must ' +
'have a prototype.'); 'have a prototype');
ctor.super_ = superCtor; ctor.super_ = superCtor;
Object.setPrototypeOf(ctor.prototype, superCtor.prototype); Object.setPrototypeOf(ctor.prototype, superCtor.prototype);

View File

@ -7,7 +7,7 @@ const util = require('util');
const assert = require('assert').ok; const assert = require('assert').ok;
const kMaxLength = require('buffer').kMaxLength; const kMaxLength = require('buffer').kMaxLength;
const kRangeErrorMessage = 'Cannot create final Buffer. ' + const kRangeErrorMessage = 'Cannot create final Buffer. ' +
'It would be larger than 0x' + kMaxLength.toString(16) + ' bytes.'; 'It would be larger than 0x' + kMaxLength.toString(16) + ' bytes';
// zlib doesn't provide these, so kludge them in following the same // zlib doesn't provide these, so kludge them in following the same
// const naming scheme zlib uses. // const naming scheme zlib uses.