diff --git a/packages/serialport-util/packages/node-serialport/lib/bindings-darwin.js b/packages/serialport-util/packages/node-serialport/lib/bindings-darwin.js index 8777de721f..f46ca14059 100644 --- a/packages/serialport-util/packages/node-serialport/lib/bindings-darwin.js +++ b/packages/serialport-util/packages/node-serialport/lib/bindings-darwin.js @@ -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 || {}; @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { diff --git a/packages/serialport-util/packages/node-serialport/lib/bindings-linux.js b/packages/serialport-util/packages/node-serialport/lib/bindings-linux.js index 7163fa2d01..772004e1f1 100644 --- a/packages/serialport-util/packages/node-serialport/lib/bindings-linux.js +++ b/packages/serialport-util/packages/node-serialport/lib/bindings-linux.js @@ -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 || {}; @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { diff --git a/packages/serialport-util/packages/node-serialport/lib/bindings-mock.js b/packages/serialport-util/packages/node-serialport/lib/bindings-mock.js index 36339f4f85..f4a13a17ca 100644 --- a/packages/serialport-util/packages/node-serialport/lib/bindings-mock.js +++ b/packages/serialport-util/packages/node-serialport/lib/bindings-mock.js @@ -9,7 +9,7 @@ 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); } @@ -17,7 +17,7 @@ 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); } @@ -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; @@ -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); }; @@ -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; @@ -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; @@ -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) { @@ -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) { @@ -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) { @@ -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) { diff --git a/packages/serialport-util/packages/node-serialport/lib/bindings-win32.js b/packages/serialport-util/packages/node-serialport/lib/bindings-win32.js index 07db1b880f..a5b74f6be4 100644 --- a/packages/serialport-util/packages/node-serialport/lib/bindings-win32.js +++ b/packages/serialport-util/packages/node-serialport/lib/bindings-win32.js @@ -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; @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { diff --git a/packages/serialport-util/packages/node-serialport/lib/parser-byte-length.js b/packages/serialport-util/packages/node-serialport/lib/parser-byte-length.js index 7dee4eafa6..116b228a40 100644 --- a/packages/serialport-util/packages/node-serialport/lib/parser-byte-length.js +++ b/packages/serialport-util/packages/node-serialport/lib/parser-byte-length.js @@ -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; diff --git a/packages/serialport-util/packages/node-serialport/lib/parser-delimiter.js b/packages/serialport-util/packages/node-serialport/lib/parser-delimiter.js index 66852bd387..31c7c601aa 100644 --- a/packages/serialport-util/packages/node-serialport/lib/parser-delimiter.js +++ b/packages/serialport-util/packages/node-serialport/lib/parser-delimiter.js @@ -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); diff --git a/packages/serialport-util/packages/node-serialport/lib/push-methods.js b/packages/serialport-util/packages/node-serialport/lib/push-methods.js index 313aa1ff36..8b68dc46b1 100644 --- a/packages/serialport-util/packages/node-serialport/lib/push-methods.js +++ b/packages/serialport-util/packages/node-serialport/lib/push-methods.js @@ -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; diff --git a/packages/serialport-util/packages/node-serialport/src/read-poller.cpp b/packages/serialport-util/packages/node-serialport/src/read-poller.cpp index fb0de0dd2d..1e3cf0135d 100644 --- a/packages/serialport-util/packages/node-serialport/src/read-poller.cpp +++ b/packages/serialport-util/packages/node-serialport/src/read-poller.cpp @@ -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; } diff --git a/packages/serialport-util/packages/node-serialport/src/serialport.cpp b/packages/serialport-util/packages/node-serialport/src/serialport.cpp index 3eec33c1f0..c7963c6c97 100644 --- a/packages/serialport-util/packages/node-serialport/src/serialport.cpp +++ b/packages/serialport-util/packages/node-serialport/src/serialport.cpp @@ -187,7 +187,7 @@ NAN_METHOD(Update) { v8::Local options = info[1]->ToObject(); if (!Nan::Has(options, Nan::New("baudRate").ToLocalChecked()).FromMaybe(false)) { - Nan::ThrowTypeError("baudRate must be set on options object"); + Nan::ThrowTypeError("\"baudRate\" must be set on options object"); return; } @@ -311,7 +311,7 @@ void EIO_AfterWrite(uv_work_t* req) { int fd = data->fd; _WriteQueue *q = qForFD(fd); if (!q) { - Nan::ThrowTypeError("There's no write queue for that file descriptor (after write)!"); + Nan::ThrowTypeError("There's no write queue for that file descriptor (after write)"); return; } diff --git a/packages/serialport-util/packages/node-serialport/src/serialport_win.cpp b/packages/serialport-util/packages/node-serialport/src/serialport_win.cpp index f853a65e98..66654cff6a 100644 --- a/packages/serialport-util/packages/node-serialport/src/serialport_win.cpp +++ b/packages/serialport-util/packages/node-serialport/src/serialport_win.cpp @@ -27,7 +27,7 @@ void ErrorCodeToString(const char* prefix, int errorCode, char *errorStr) { _snprintf_s(errorStr, ERROR_STRING_SIZE, _TRUNCATE, "%s: Access denied", prefix); break; case ERROR_OPERATION_ABORTED: - _snprintf_s(errorStr, ERROR_STRING_SIZE, _TRUNCATE, "%s: operation aborted", prefix); + _snprintf_s(errorStr, ERROR_STRING_SIZE, _TRUNCATE, "%s: Operation aborted", prefix); break; default: _snprintf_s(errorStr, ERROR_STRING_SIZE, _TRUNCATE, "%s: Unknown error code %d", prefix, errorCode); @@ -175,14 +175,14 @@ void EIO_Update(uv_work_t* req) { dcb.DCBlength = sizeof(DCB); if (!GetCommState((HANDLE)data->fd, &dcb)) { - ErrorCodeToString("GetCommState", GetLastError(), data->errorString); + ErrorCodeToString("Update (GetCommState)", GetLastError(), data->errorString); return; } dcb.BaudRate = data->baudRate; if (!SetCommState((HANDLE)data->fd, &dcb)) { - ErrorCodeToString("SetCommState", GetLastError(), data->errorString); + ErrorCodeToString("Update (SetCommState)", GetLastError(), data->errorString); return; } } @@ -326,7 +326,7 @@ void EIO_Close(uv_work_t* req) { pCancelIoEx((HANDLE)data->fd, NULL); } if (!CloseHandle((HANDLE)data->fd)) { - ErrorCodeToString("closing connection", GetLastError(), data->errorString); + ErrorCodeToString("Closing connection (CloseHandle)", GetLastError(), data->errorString); return; } } @@ -421,7 +421,7 @@ void EIO_Flush(uv_work_t* req) { DWORD purge_all = PURGE_RXABORT | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_TXCLEAR; if (!PurgeComm((HANDLE)data->fd, purge_all)) { - ErrorCodeToString("flushing connection (PurgeComm)", GetLastError(), data->errorString); + ErrorCodeToString("Flushing connection (PurgeComm)", GetLastError(), data->errorString); return; } } @@ -430,7 +430,7 @@ void EIO_Drain(uv_work_t* req) { VoidBaton* data = static_cast(req->data); if (!FlushFileBuffers((HANDLE)data->fd)) { - ErrorCodeToString("draining connection (FlushFileBuffers)", GetLastError(), data->errorString); + ErrorCodeToString("Draining connection (FlushFileBuffers)", GetLastError(), data->errorString); return; } } diff --git a/packages/serialport-util/packages/node-serialport/test/bindings.js b/packages/serialport-util/packages/node-serialport/test/bindings.js index ca0c255ec4..e7702c869b 100644 --- a/packages/serialport-util/packages/node-serialport/test/bindings.js +++ b/packages/serialport-util/packages/node-serialport/test/bindings.js @@ -42,7 +42,7 @@ var bindingsToTest = [ ]; function disconnect(err) { - throw (err || new Error('disconnected')); + throw (err || new Error('Disconnected')); } // All bindings are required to work with an "echo" firmware diff --git a/packages/serialport-util/packages/node-serialport/test/mocks/list-linux.js b/packages/serialport-util/packages/node-serialport/test/mocks/list-linux.js index dc86747c93..7e148f74a7 100644 --- a/packages/serialport-util/packages/node-serialport/test/mocks/list-linux.js +++ b/packages/serialport-util/packages/node-serialport/test/mocks/list-linux.js @@ -13,7 +13,7 @@ var listLinux = proxyquire('../../lib/list-linux', { readdir: function(path, cb) { if (error) { return process.nextTick(function() { - cb(new Error('bad')); + cb(new Error('Bad')); }); } process.nextTick(function() { diff --git a/packages/serialport-util/packages/node-serialport/test/serialport.js b/packages/serialport-util/packages/node-serialport/test/serialport.js index 0c813f0546..ccb1066289 100644 --- a/packages/serialport-util/packages/node-serialport/test/serialport.js +++ b/packages/serialport-util/packages/node-serialport/test/serialport.js @@ -332,7 +332,7 @@ describe('SerialPort', function() { it('allows opening after an open error', function(done) { var port = new SerialPort('/dev/exists', { autoOpen: false }); var stub = sandbox.stub(port.binding, 'open', function(path, opt, cb) { - cb(new Error('haha no')); + cb(new Error('Haha no')); }); port.open(function(err) { assert.instanceOf(err, Error);