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

Consistent error messages in all modules #3374

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: 2 additions & 2 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ function ClientRequest(options, cb) {
// well, and b) possibly too restrictive for real-world usage. That's
// why it only scans for spaces because those are guaranteed to create
// an invalid request.
throw new TypeError('Request path contains unescaped characters.');
throw new TypeError('Request path contains unescaped characters');
} else if (protocol !== expectedProtocol) {
throw new Error('Protocol "' + protocol + '" not supported. ' +
'Expected "' + expectedProtocol + '".');
'Expected "' + expectedProtocol + '"');
}

const defaultPort = options.defaultPort ||
Expand Down
18 changes: 9 additions & 9 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,11 @@ OutgoingMessage.prototype.setHeader = function(name, value) {
throw new TypeError(
'Header name must be a valid HTTP Token ["' + name + '"]');
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)
throw new Error('`value` required in setHeader("' + name + '", value).');
throw new Error('"value" required in setHeader("' + name + '", value)');
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)
this._headers = {};
Expand All @@ -357,7 +357,7 @@ OutgoingMessage.prototype.setHeader = function(name, value) {

OutgoingMessage.prototype.getHeader = function(name) {
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;
Expand All @@ -369,11 +369,11 @@ OutgoingMessage.prototype.getHeader = function(name) {

OutgoingMessage.prototype.removeHeader = function(name) {
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) {
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();
Expand All @@ -392,7 +392,7 @@ OutgoingMessage.prototype.removeHeader = function(name) {

OutgoingMessage.prototype._renderHeaders = function() {
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;
Expand Down Expand Up @@ -436,7 +436,7 @@ OutgoingMessage.prototype.write = function(chunk, encoding, callback) {
}

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');
}


Expand Down Expand Up @@ -533,7 +533,7 @@ OutgoingMessage.prototype.end = function(data, encoding, callback) {
}

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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ function endReadable(stream) {
// If we get here before consuming all the bytes, then that is a
// bug in node. Should never happen.
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) {
state.ended = true;
Expand Down
6 changes: 3 additions & 3 deletions lib/_stream_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Transform.prototype.push = function(chunk, encoding) {
// an error, then that'll put the hurt on the whole operation. If you
// never call cb(), then you'll never get another chunk.
Transform.prototype._transform = function(chunk, encoding, cb) {
throw new Error('not implemented');
throw new Error('Not implemented');
};

Transform.prototype._write = function(chunk, encoding, cb) {
Expand Down Expand Up @@ -183,10 +183,10 @@ function done(stream, er) {
var ts = stream._transformState;

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)
throw new Error('calling transform done when still transforming');
throw new Error('Calling transform done when still transforming');

return stream.push(null);
}
2 changes: 1 addition & 1 deletion lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function Writable(options) {

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


Expand Down
4 changes: 2 additions & 2 deletions lib/_tls_legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var Connection = null;
try {
Connection = process.binding('crypto').Connection;
} 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() {
Expand Down Expand Up @@ -590,7 +590,7 @@ function onhandshakestart() {
// 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.
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);
});
}
Expand Down
6 changes: 3 additions & 3 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function onhandshakestart() {
// 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.
setImmediate(function() {
var err = new Error('TLS session renegotiation attack detected.');
var err = new Error('TLS session renegotiation attack detected');
self._emitTLSError(err);
});
}
Expand Down Expand Up @@ -756,7 +756,7 @@ function Server(/* [options], listener */) {
var timeout = options.handshakeTimeout || (120 * 1000);

if (typeof timeout !== 'number') {
throw new TypeError('handshakeTimeout must be a number');
throw new TypeError('"handshakeTimeout" option must be a number');
}

if (self.sessionTimeout) {
Expand Down Expand Up @@ -902,7 +902,7 @@ Server.prototype.setOptions = function(options) {
// SNI Contexts High-Level API
Server.prototype.addContext = function(servername, context) {
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('^' +
Expand Down
2 changes: 1 addition & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ function _throws(shouldThrow, block, expected, message) {
var actual;

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') {
Expand Down
30 changes: 15 additions & 15 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function fromObject(obj) {
}

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) {
Expand Down Expand Up @@ -164,7 +164,7 @@ function fromObject(obj) {
return b;
}

throw new TypeError('must start with number, buffer, array or string');
throw new TypeError('Must start with number, buffer, array or string');
}


Expand Down Expand Up @@ -217,7 +217,7 @@ Buffer.isEncoding = function(encoding) {

Buffer.concat = function(list, length) {
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)
return new Buffer(0);
Expand Down Expand Up @@ -375,7 +375,7 @@ Buffer.prototype.toString = function() {
var result = slowToString.apply(this, arguments);
}
if (result === undefined)
throw new Error('toString failed');
throw new Error('"toString()" failed');
return result;
};

Expand Down Expand Up @@ -462,7 +462,7 @@ Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
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');
};


Expand All @@ -471,7 +471,7 @@ Buffer.prototype.fill = function fill(val, start, end) {
end = (end === undefined) ? this.length : end >> 0;

if (start < 0 || end > this.length)
throw new RangeError('out of range index');
throw new RangeError('Out of range index');
if (end <= start)
return this;

Expand All @@ -493,7 +493,7 @@ Buffer.prototype.fill = function fill(val, start, end) {
Buffer.prototype.get = internalUtil.deprecate(function get(offset) {
offset = ~~offset;
if (offset < 0 || offset >= this.length)
throw new RangeError('index out of range');
throw new RangeError('Index out of range');
return this[offset];
}, 'Buffer.get is deprecated. Use array indexes instead.');

Expand All @@ -502,7 +502,7 @@ Buffer.prototype.get = internalUtil.deprecate(function get(offset) {
Buffer.prototype.set = internalUtil.deprecate(function set(offset, v) {
offset = ~~offset;
if (offset < 0 || offset >= this.length)
throw new RangeError('index out of range');
throw new RangeError('Index out of range');
return this[offset] = v;
}, 'Buffer.set is deprecated. Use array indexes instead.');

Expand Down Expand Up @@ -552,7 +552,7 @@ Buffer.prototype.write = function(string, offset, length, encoding) {
length = remaining;

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)
encoding = 'utf8';
Expand Down Expand Up @@ -612,7 +612,7 @@ Buffer.prototype.slice = function slice(start, end) {

function checkOffset(offset, ext, length) {
if (offset + ext > length)
throw new RangeError('index out of range');
throw new RangeError('Index out of range');
}


Expand Down Expand Up @@ -820,11 +820,11 @@ Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {

function checkInt(buffer, value, offset, ext, max, min) {
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)
throw new TypeError('value is out of bounds');
throw new TypeError('"value" argument is out of bounds');
if (offset + ext > buffer.length)
throw new RangeError('index out of range');
throw new RangeError('Index out of range');
}


Expand Down Expand Up @@ -1030,9 +1030,9 @@ Buffer.prototype.writeInt32BE = function(value, offset, noAssert) {

function checkFloat(buffer, value, offset, ext) {
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)
throw new RangeError('index out of range');
throw new RangeError('Index out of range');
}


Expand Down
6 changes: 3 additions & 3 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ exports.execFile = function(file /*, args, options, callback*/) {
stdoutLen += chunk.length;

if (stdoutLen > options.maxBuffer) {
ex = new Error('stdout maxBuffer exceeded.');
ex = new Error('stdout maxBuffer exceeded');
kill();
} else {
if (!encoding)
Expand All @@ -265,7 +265,7 @@ exports.execFile = function(file /*, args, options, callback*/) {
stderrLen += chunk.length;

if (stderrLen > options.maxBuffer) {
ex = new Error('stderr maxBuffer exceeded.');
ex = new Error('stderr maxBuffer exceeded');
kill();
} else {
if (!encoding)
Expand Down Expand Up @@ -316,7 +316,7 @@ function normalizeSpawnArguments(file /*, args, options*/) {
if (options === undefined)
options = {};
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);
args.unshift(file);
Expand Down
8 changes: 4 additions & 4 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ try {
var getHashes = binding.getHashes;
var getCurves = binding.getCurves;
} 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;
Expand Down Expand Up @@ -486,7 +486,7 @@ DiffieHellman.prototype.setPrivateKey = function(key, encoding) {

function ECDH(curve) {
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);
}
Expand Down Expand Up @@ -604,10 +604,10 @@ Certificate.prototype.exportChallenge = function(object, encoding) {

exports.setEngine = function setEngine(id, flags) {
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')
throw new TypeError('flags should be a number, if present');
throw new TypeError('"flags" argument should be a number, if present');
flags = flags >>> 0;

// Use provided engine for everything by default
Expand Down
8 changes: 4 additions & 4 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function newHandle(type) {
}

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');
}
Expand Down Expand Up @@ -233,7 +233,7 @@ Socket.prototype.sendto = function(buffer,
address,
callback) {
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')
throw new Error(this.type + ' sockets must send to port, address');
Expand All @@ -254,15 +254,15 @@ Socket.prototype.send = function(buffer,
buffer = new Buffer(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;
if (offset < 0)
throw new RangeError('Offset should be >= 0');

if ((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_
// allowed, hence check that length >= 0 rather than > 0.
Expand Down
Loading