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 #892

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
18 changes: 9 additions & 9 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ function storeHeader(self, state, field, value) {

OutgoingMessage.prototype.setHeader = function(name, value) {
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" is 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 @@ -345,7 +345,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" is required for getHeader(name)');
}

if (!this._headers) return;
Expand All @@ -357,11 +357,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" 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 @@ -380,7 +380,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 @@ -424,7 +424,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 @@ -511,7 +511,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
4 changes: 2 additions & 2 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ function maybeReadMore_(stream, state) {
// for virtual (non-string, non-buffer) streams, "length" is somewhat
// arbitrary, and perhaps not very meaningful.
Readable.prototype._read = function(n) {
this.emit('error', new Error('not implemented'));
this.emit('error', new Error('Not implemented'));
};

Readable.prototype.pipe = function(dest, pipeOpts) {
Expand Down Expand Up @@ -874,7 +874,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
8 changes: 4 additions & 4 deletions lib/_stream_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function afterTransform(stream, er, data) {
var cb = ts.writecb;

if (!cb)
return stream.emit('error', new Error('no writecb in Transform class'));
return stream.emit('error', new Error('No "writecb" in Transform class'));

ts.writechunk = null;
ts.writecb = null;
Expand Down 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);
}
4 changes: 2 additions & 2 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Writable.prototype.pipe = function() {


function writeAfterEnd(stream, cb) {
var er = new Error('write after end');
var er = new Error('Write after end');
// TODO: defer error events consistently everywhere, not just the cb
stream.emit('error', er);
process.nextTick(cb, er);
Expand Down Expand Up @@ -417,7 +417,7 @@ function clearBuffer(stream, state) {
}

Writable.prototype._write = function(chunk, encoding, cb) {
cb(new Error('not implemented'));
cb(new Error('Not implemented'));
};

Writable.prototype._writev = null;
Expand Down
2 changes: 1 addition & 1 deletion lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,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
2 changes: 1 addition & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,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
20 changes: 10 additions & 10 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,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('Index out of range');
if (end <= start)
return this;

Expand All @@ -426,7 +426,7 @@ Buffer.prototype.fill = function fill(val, start, end) {
Buffer.prototype.get = util.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];
}, '.get() is deprecated. Access using array indexes instead.');

Expand All @@ -435,7 +435,7 @@ Buffer.prototype.get = util.deprecate(function get(offset) {
Buffer.prototype.set = util.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;
}, '.set() is deprecated. Set using array indexes instead.');

Expand Down Expand Up @@ -493,7 +493,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 @@ -580,7 +580,7 @@ Buffer.prototype.slice = function(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 @@ -788,11 +788,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 RangeError('"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 @@ -994,9 +994,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
8 changes: 4 additions & 4 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ function setupChannel(target, channel) {

target.send = function(message, handle) {
if (!this.connected)
this.emit('error', new Error('channel closed'));
this.emit('error', new Error('Channel closed'));
else
this._send(message, handle, false);
};
Expand All @@ -372,7 +372,7 @@ function setupChannel(target, channel) {
assert(this.connected || this._channel);

if (message === undefined)
throw new TypeError('message cannot be undefined');
throw new TypeError('"message" argument cannot be undefined');

// package messages with a handle object
if (handle) {
Expand All @@ -394,7 +394,7 @@ function setupChannel(target, channel) {
} else if (handle instanceof UDP) {
message.type = 'dgram.Native';
} 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.
Expand Down Expand Up @@ -900,7 +900,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
6 changes: 3 additions & 3 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small question: Every other error is something line ".... must be ...". Does it make sense to change it also in crypto?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have a compromise on this yet (should vs must) see https://tools.ietf.org/html/rfc2119


this._handle = new binding.ECDH(curve);
}
Expand Down Expand Up @@ -634,10 +634,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
4 changes: 2 additions & 2 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ Socket.prototype.addMembership = function(multicastAddress,
this._healthCheck();

if (!multicastAddress) {
throw new Error('multicast address must be specified');
throw new Error('Multicast address must be specified');
}

var err = this._handle.addMembership(multicastAddress, interfaceAddress);
Expand All @@ -440,7 +440,7 @@ Socket.prototype.dropMembership = function(multicastAddress,
this._healthCheck();

if (!multicastAddress) {
throw new Error('multicast address must be specified');
throw new Error('Multicast address must be specified');
}

var err = this._handle.dropMembership(multicastAddress, interfaceAddress);
Expand Down
14 changes: 7 additions & 7 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ exports.lookup = function lookup(hostname, options, callback) {
hints !== exports.ADDRCONFIG &&
hints !== 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');
}

// FIXME(indutny): V4MAPPED on FreeBSD results in EAI_BADFLAGS, because
Expand All @@ -138,7 +138,7 @@ exports.lookup = function lookup(hostname, options, callback) {
}

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

Expand Down Expand Up @@ -189,10 +189,10 @@ function onlookupservice(err, host, service) {
// lookupService(address, port, callback)
exports.lookupService = function(host, port, callback) {
if (arguments.length !== 3)
throw new Error('invalid arguments');
throw new Error('Invalid arguments');

if (cares.isIP(host) === 0)
throw new TypeError('host needs to be a valid IP address');
throw new TypeError('"host" argument must be a valid IP address');

callback = makeAsync(callback);

Expand Down Expand Up @@ -223,9 +223,9 @@ function resolver(bindingName) {

return function query(name, callback) {
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') {
throw new Error('Callback must be a function');
throw new Error('"callback" argument must be a function');
}

callback = makeAsync(callback);
Expand Down Expand Up @@ -265,7 +265,7 @@ exports.resolve = function(hostname, type_, callback_) {
resolver = exports.resolve4;
callback = type_;
} else {
throw new Error('Type must be a string');
throw new Error('"type" argument must be a string');
}

if (typeof resolver === 'function') {
Expand Down
8 changes: 4 additions & 4 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ EventEmitter.init = function() {
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function setMaxListeners(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;
return this;
};
Expand Down Expand Up @@ -191,7 +191,7 @@ EventEmitter.prototype.addListener = function addListener(type, listener) {
var existing;

if (typeof listener !== 'function')
throw new TypeError('listener must be a function');
throw new TypeError('"listener" argument must be a function');

events = this._events;
if (!events) {
Expand Down Expand Up @@ -245,7 +245,7 @@ EventEmitter.prototype.on = EventEmitter.prototype.addListener;

EventEmitter.prototype.once = function once(type, listener) {
if (typeof listener !== 'function')
throw new TypeError('listener must be a function');
throw new TypeError('"listener" argument must be a function');

var fired = false;

Expand All @@ -270,7 +270,7 @@ EventEmitter.prototype.removeListener =
var list, events, position, i;

if (typeof listener !== 'function')
throw new TypeError('listener must be a function');
throw new TypeError('"listener" argument must be a function');

events = this._events;
if (!events)
Expand Down
Loading