Skip to content
Permalink
Browse files

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: #3374
Reviewed-By: Roman Reiss <me@silverwind.io>
  • Loading branch information...
micnic authored and silverwind committed Oct 14, 2015
1 parent af46112 commit 20285ad17755187ece16b8a5effeaa87f5407da2
@@ -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 ||
@@ -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 = {};
@@ -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;
@@ -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();
@@ -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;
@@ -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');
}


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


@@ -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() {
@@ -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);
});
}
@@ -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);
});
}
@@ -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) {
@@ -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('^' +
@@ -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') {
@@ -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) {
@@ -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');
}


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

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


@@ -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;

@@ -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.');

@@ -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.');

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


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


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


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

0 comments on commit 20285ad

Please sign in to comment.
You can’t perform that action at this time.