Skip to content

Commit

Permalink
Conform to NodeJS error message formats (#998)
Browse files Browse the repository at this point in the history
  • Loading branch information
reconbot committed Jul 24, 2018
1 parent ecda71b commit b1772d7
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ function asyncError(cb, err) {

function DarwinBinding(opt) {
if (typeof opt !== 'object') {
throw new TypeError('options is not an object');
throw new TypeError('"options" is not an object');
}
if (typeof opt.disconnect !== 'function') {
throw new TypeError('options.disconnect is not a function');
throw new TypeError('"options.disconnect" is not a function');
}
this.disconnect = opt.disconnect;
this.bindingOptions = opt.bindingOptions || {};
Expand All @@ -32,15 +32,15 @@ DarwinBinding.prototype.read = require('./read-unix');

DarwinBinding.prototype.open = function(path, options, cb) {
if (typeof path !== 'string') {
throw new TypeError('path is not a string');
throw new TypeError('"path" is not a string');
}

if (typeof options !== 'object') {
throw new TypeError('options is not an object');
throw new TypeError('"options" is not an object');
}

if (typeof cb !== 'function') {
throw new TypeError('cb is not a function');
throw new TypeError('"cb" is not a function');
}

if (this.isOpen) {
Expand All @@ -60,7 +60,7 @@ DarwinBinding.prototype.open = function(path, options, cb) {

DarwinBinding.prototype.close = function(cb) {
if (typeof cb !== 'function') {
throw new TypeError('cb is not a function');
throw new TypeError('"cb" is not a function');
}

if (!this.isOpen) {
Expand All @@ -83,11 +83,11 @@ DarwinBinding.prototype.close = function(cb) {

DarwinBinding.prototype.set = function(options, cb) {
if (typeof options !== 'object') {
throw new TypeError('options is not an object');
throw new TypeError('"options" is not an object');
}

if (typeof cb !== 'function') {
throw new TypeError('cb is not a function');
throw new TypeError('"cb" is not a function');
}

if (!this.isOpen) {
Expand All @@ -98,11 +98,11 @@ DarwinBinding.prototype.set = function(options, cb) {

DarwinBinding.prototype.write = function(buffer, cb) {
if (!Buffer.isBuffer(buffer)) {
throw new TypeError('buffer is not a Buffer');
throw new TypeError('"buffer" is not a Buffer');
}

if (typeof cb !== 'function') {
throw new TypeError('cb is not a function');
throw new TypeError('"cb" is not a function');
}

if (!this.isOpen) {
Expand All @@ -125,7 +125,7 @@ commonMethods.map(function(methodName) {
var cb = args[args.length - 1];

if (typeof cb !== 'function') {
throw new TypeError('cb is not a function');
throw new TypeError('"cb" is not a function');
}

if (!this.isOpen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ function asyncError(cb, err) {

function LinuxBinding(opt) {
if (typeof opt !== 'object') {
throw new TypeError('options is not an object');
throw new TypeError('"options" is not an object');
}
if (typeof opt.disconnect !== 'function') {
throw new TypeError('options.disconnect is not a function');
throw new TypeError('"options.disconnect" is not a function');
}
this.disconnect = opt.disconnect;
this.bindingOptions = opt.bindingOptions || {};
Expand All @@ -32,15 +32,15 @@ LinuxBinding.prototype.read = require('./read-unix');

LinuxBinding.prototype.open = function(path, options, cb) {
if (typeof path !== 'string') {
throw new TypeError('path is not a string');
throw new TypeError('"path" is not a string');
}

if (typeof options !== 'object') {
throw new TypeError('options is not an object');
throw new TypeError('"options" is not an object');
}

if (typeof cb !== 'function') {
throw new TypeError('cb is not a function');
throw new TypeError('"cb" is not a function');
}

if (this.isOpen) {
Expand All @@ -60,7 +60,7 @@ LinuxBinding.prototype.open = function(path, options, cb) {

LinuxBinding.prototype.close = function(cb) {
if (typeof cb !== 'function') {
throw new TypeError('cb is not a function');
throw new TypeError('"cb" is not a function');
}

if (!this.isOpen) {
Expand All @@ -83,11 +83,11 @@ LinuxBinding.prototype.close = function(cb) {

LinuxBinding.prototype.set = function(options, cb) {
if (typeof options !== 'object') {
throw new TypeError('options is not an object');
throw new TypeError('"options" is not an object');
}

if (typeof cb !== 'function') {
throw new TypeError('cb is not a function');
throw new TypeError('"cb" is not a function');
}

if (!this.isOpen) {
Expand All @@ -98,11 +98,11 @@ LinuxBinding.prototype.set = function(options, cb) {

LinuxBinding.prototype.write = function(buffer, cb) {
if (!Buffer.isBuffer(buffer)) {
throw new TypeError('buffer is not a Buffer');
throw new TypeError('"buffer" is not a Buffer');
}

if (typeof cb !== 'function') {
throw new TypeError('cb is not a function');
throw new TypeError('"cb" is not a function');
}

if (!this.isOpen) {
Expand All @@ -124,7 +124,7 @@ commonMethods.map(function(methodName) {
var cb = args[args.length - 1];

if (typeof cb !== 'function') {
throw new TypeError('cb is not a function');
throw new TypeError('"cb" is not a function');
}

if (!this.isOpen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ var processNextTick = function() {

function MissingPortError(name) {
name = name || 'unknown method:';
this.message = name + ' Port does not exist - please call hardware.createPort(path) first';
this.message = 'Port does not exist - please call hardware.createPort(path) first: ' + name;
this.name = 'MissingPortError';
Error.captureStackTrace(this, MissingPortError);
}
inherits(MissingPortError, Error);

function ClosedPortError(name) {
name = name || 'unknown method:';
this.message = name + ' Port is closed';
this.message = 'Port is closed: ' + name;
this.name = 'ClosedPortError';
Error.captureStackTrace(this, MissingPortError);
}
Expand All @@ -27,7 +27,7 @@ var ports = {};

function MockBindings(opt) {
if (typeof opt.disconnect !== 'function') {
throw new TypeError('options.disconnect is not a function');
throw new TypeError('"options.disconnect" is not a function');
}
this.onDisconnect = opt.disconnect;
this.pendingReadCB = null;
Expand Down Expand Up @@ -85,7 +85,7 @@ MockBindings.prototype.emitData = function(data) {
};

MockBindings.prototype.disconnect = function(err) {
err = err || new Error('disconnected');
err = err || new Error('Disconnected');
this.onDisconnect(err);
};

Expand All @@ -96,11 +96,11 @@ MockBindings.prototype.open = function(path, opt, cb) {
}

if (port.openOpt && port.openOpt.lock) {
return cb(new Error('port is locked cannot open'));
return cb(new Error('Port is locked cannot open'));
}

if (this.isOpen) {
return processNextTick(cb, new Error('open: binding is already open'));
return processNextTick(cb, new Error('Open: binding is already open'));
}

port.openOpt = opt;
Expand All @@ -118,7 +118,7 @@ MockBindings.prototype.open = function(path, opt, cb) {
MockBindings.prototype.close = function(cb) {
var port = this.port;
if (!port) {
return processNextTick(cb, new Error('port is already closed'));
return processNextTick(cb, new ClosedPortError('close'));
}
processNextTick(function() {
delete port.openOpt;
Expand All @@ -134,11 +134,11 @@ MockBindings.prototype.close = function(cb) {

MockBindings.prototype.update = function(opt, cb) {
if (typeof opt !== 'object') {
throw new TypeError('options is not an object');
throw new TypeError('"options" is not an object');
}

if (!opt.baudRate) {
throw new Error('Missing baudRate');
if (typeof opt.baudRate !== 'number') {
throw new TypeError('"options.baudRate" is not a number');
}

if (!this.isOpen) {
Expand All @@ -150,7 +150,7 @@ MockBindings.prototype.update = function(opt, cb) {

MockBindings.prototype.set = function(opt, cb) {
if (typeof opt !== 'object') {
throw new TypeError('options is not an object');
throw new TypeError('"options" is not an object');
}

if (!this.isOpen) {
Expand All @@ -161,11 +161,11 @@ MockBindings.prototype.set = function(opt, cb) {

MockBindings.prototype.write = function(buffer, cb) {
if (!Buffer.isBuffer(buffer)) {
throw new TypeError('buffer is not a Buffer');
throw new TypeError('"buffer" is not a Buffer');
}

if (typeof cb !== 'function') {
throw new TypeError('callback is not a function');
throw new TypeError('"cb" is not a function');
}

if (!this.isOpen) {
Expand All @@ -182,7 +182,7 @@ MockBindings.prototype.write = function(buffer, cb) {

MockBindings.prototype.read = function(buffer, offset, length, cb) {
if (typeof cb !== 'function') {
throw new TypeError("cb in read isn't a function");
throw new TypeError('"cb" in read is not a function');
}

if (!this.isOpen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ function asyncError(cb, err) {

function WindowsBinding(opt) {
if (typeof opt !== 'object') {
throw new TypeError('options is not an object');
throw new TypeError('"options" is not an object');
}
if (typeof opt.disconnect !== 'function') {
throw new TypeError('options.disconnect is not a function');
throw new TypeError('"options.disconnect" is not a function');
}
this.disconnect = opt.disconnect;
this.fd = null;
Expand All @@ -23,15 +23,15 @@ WindowsBinding.prototype.read = require('./read-unix');

WindowsBinding.prototype.open = function(path, options, cb) {
if (typeof path !== 'string') {
throw new TypeError('path is not a string');
throw new TypeError('"path" is not a string');
}

if (typeof options !== 'object') {
throw new TypeError('options is not an object');
throw new TypeError('"options" is not an object');
}

if (typeof cb !== 'function') {
throw new TypeError('cb is not a function');
throw new TypeError('"cb" is not a function');
}

if (this.isOpen) {
Expand All @@ -49,7 +49,7 @@ WindowsBinding.prototype.open = function(path, options, cb) {

WindowsBinding.prototype.close = function(cb) {
if (typeof cb !== 'function') {
throw new TypeError('cb is not a function');
throw new TypeError('"cb" is not a function');
}

if (!this.isOpen) {
Expand All @@ -72,11 +72,11 @@ WindowsBinding.prototype.close = function(cb) {

WindowsBinding.prototype.set = function(options, cb) {
if (typeof options !== 'object') {
throw new TypeError('options is not an object');
throw new TypeError('"options" is not an object');
}

if (typeof cb !== 'function') {
throw new TypeError('cb is not a function');
throw new TypeError('"cb" is not a function');
}

if (!this.isOpen) {
Expand All @@ -88,11 +88,11 @@ WindowsBinding.prototype.set = function(options, cb) {

WindowsBinding.prototype.write = function(buffer, cb) {
if (!Buffer.isBuffer(buffer)) {
throw new TypeError('buffer is not a Buffer');
throw new TypeError('"buffer" is not a Buffer');
}

if (typeof cb !== 'function') {
throw new TypeError('cb is not a function');
throw new TypeError('"cb" is not a function');
}

if (!this.isOpen) {
Expand All @@ -115,7 +115,7 @@ commonMethods.map(function(methodName) {
var cb = args[args.length - 1];

if (typeof cb !== 'function') {
throw new TypeError('cb is not a function');
throw new TypeError('"cb" is not a function');
}

if (!this.isOpen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ function ByteLengthParser(options) {
options = options || {};

if (typeof options.length !== 'number') {
throw new TypeError('length is not a number');
throw new TypeError('"length" is not a number');
}

if (options.length < 1) {
throw new TypeError('length is not greater than 0');
throw new TypeError('"length" is not greater than 0');
}

this.length = options.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ function DelimiterParser(options) {
options = options || {};

if (options.delimiter === undefined) {
throw new TypeError('delimiter is not a bufferable object');
throw new TypeError('"delimiter" is not a bufferable object');
}

if (options.delimiter.length === 0) {
throw new TypeError('delimiter has a 0 or undefined length');
throw new TypeError('"delimiter" has a 0 or undefined length');
}

this.delimiter = new Buffer(options.delimiter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ function _read(bytesToRead) {

function pushBindingWrap(opt) {
if (typeof opt.binding !== 'object') {
throw new TypeError('binding is not an object');
throw new TypeError('"binding" is not an object');
}
if (typeof opt.push !== 'function') {
throw new TypeError('push is not a function');
throw new TypeError('"push" is not a function');
}

var binding = opt.binding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void ReadPoller::callCallback(int status) {
NAN_METHOD(ReadPoller::New) {
// printf("ReadPoller\n");
if (!info[0]->IsInt32()) {
Nan::ThrowTypeError("First argument must be an fd");
Nan::ThrowTypeError("First argument must be an integer file descriptor");
return;
}

Expand Down
Loading

0 comments on commit b1772d7

Please sign in to comment.