Skip to content

Commit fe15480

Browse files
committed
Conform to NodeJS error message formats
nodejs/node#3374
1 parent 77c351e commit fe15480

13 files changed

+65
-65
lines changed

lib/bindings-darwin.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ function asyncError(cb, err) {
1616

1717
function DarwinBinding(opt) {
1818
if (typeof opt !== 'object') {
19-
throw new TypeError('options is not an object');
19+
throw new TypeError('"options" is not an object');
2020
}
2121
if (typeof opt.disconnect !== 'function') {
22-
throw new TypeError('options.disconnect is not a function');
22+
throw new TypeError('"options.disconnect" is not a function');
2323
}
2424
this.disconnect = opt.disconnect;
2525
this.bindingOptions = opt.bindingOptions || {};
@@ -32,15 +32,15 @@ DarwinBinding.prototype.read = require('./read-unix');
3232

3333
DarwinBinding.prototype.open = function(path, options, cb) {
3434
if (typeof path !== 'string') {
35-
throw new TypeError('path is not a string');
35+
throw new TypeError('"path" is not a string');
3636
}
3737

3838
if (typeof options !== 'object') {
39-
throw new TypeError('options is not an object');
39+
throw new TypeError('"options" is not an object');
4040
}
4141

4242
if (typeof cb !== 'function') {
43-
throw new TypeError('cb is not a function');
43+
throw new TypeError('"cb" is not a function');
4444
}
4545

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

6161
DarwinBinding.prototype.close = function(cb) {
6262
if (typeof cb !== 'function') {
63-
throw new TypeError('cb is not a function');
63+
throw new TypeError('"cb" is not a function');
6464
}
6565

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

8484
DarwinBinding.prototype.set = function(options, cb) {
8585
if (typeof options !== 'object') {
86-
throw new TypeError('options is not an object');
86+
throw new TypeError('"options" is not an object');
8787
}
8888

8989
if (typeof cb !== 'function') {
90-
throw new TypeError('cb is not a function');
90+
throw new TypeError('"cb" is not a function');
9191
}
9292

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

9999
DarwinBinding.prototype.write = function(buffer, cb) {
100100
if (!Buffer.isBuffer(buffer)) {
101-
throw new TypeError('buffer is not a Buffer');
101+
throw new TypeError('"buffer" is not a Buffer');
102102
}
103103

104104
if (typeof cb !== 'function') {
105-
throw new TypeError('cb is not a function');
105+
throw new TypeError('"cb" is not a function');
106106
}
107107

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

127127
if (typeof cb !== 'function') {
128-
throw new TypeError('cb is not a function');
128+
throw new TypeError('"cb" is not a function');
129129
}
130130

131131
if (!this.isOpen) {

lib/bindings-linux.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ function asyncError(cb, err) {
1616

1717
function LinuxBinding(opt) {
1818
if (typeof opt !== 'object') {
19-
throw new TypeError('options is not an object');
19+
throw new TypeError('"options" is not an object');
2020
}
2121
if (typeof opt.disconnect !== 'function') {
22-
throw new TypeError('options.disconnect is not a function');
22+
throw new TypeError('"options.disconnect" is not a function');
2323
}
2424
this.disconnect = opt.disconnect;
2525
this.bindingOptions = opt.bindingOptions || {};
@@ -32,15 +32,15 @@ LinuxBinding.prototype.read = require('./read-unix');
3232

3333
LinuxBinding.prototype.open = function(path, options, cb) {
3434
if (typeof path !== 'string') {
35-
throw new TypeError('path is not a string');
35+
throw new TypeError('"path" is not a string');
3636
}
3737

3838
if (typeof options !== 'object') {
39-
throw new TypeError('options is not an object');
39+
throw new TypeError('"options" is not an object');
4040
}
4141

4242
if (typeof cb !== 'function') {
43-
throw new TypeError('cb is not a function');
43+
throw new TypeError('"cb" is not a function');
4444
}
4545

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

6161
LinuxBinding.prototype.close = function(cb) {
6262
if (typeof cb !== 'function') {
63-
throw new TypeError('cb is not a function');
63+
throw new TypeError('"cb" is not a function');
6464
}
6565

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

8484
LinuxBinding.prototype.set = function(options, cb) {
8585
if (typeof options !== 'object') {
86-
throw new TypeError('options is not an object');
86+
throw new TypeError('"options" is not an object');
8787
}
8888

8989
if (typeof cb !== 'function') {
90-
throw new TypeError('cb is not a function');
90+
throw new TypeError('"cb" is not a function');
9191
}
9292

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

9999
LinuxBinding.prototype.write = function(buffer, cb) {
100100
if (!Buffer.isBuffer(buffer)) {
101-
throw new TypeError('buffer is not a Buffer');
101+
throw new TypeError('"buffer" is not a Buffer');
102102
}
103103

104104
if (typeof cb !== 'function') {
105-
throw new TypeError('cb is not a function');
105+
throw new TypeError('"cb" is not a function');
106106
}
107107

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

126126
if (typeof cb !== 'function') {
127-
throw new TypeError('cb is not a function');
127+
throw new TypeError('"cb" is not a function');
128128
}
129129

130130
if (!this.isOpen) {

lib/bindings-mock.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ var processNextTick = function() {
99

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

1818
function ClosedPortError(name) {
1919
name = name || 'unknown method:';
20-
this.message = name + ' Port is closed';
20+
this.message = 'Port is closed: ' + name;
2121
this.name = 'ClosedPortError';
2222
Error.captureStackTrace(this, MissingPortError);
2323
}
@@ -27,7 +27,7 @@ var ports = {};
2727

2828
function MockBindings(opt) {
2929
if (typeof opt.disconnect !== 'function') {
30-
throw new TypeError('options.disconnect is not a function');
30+
throw new TypeError('"options.disconnect" is not a function');
3131
}
3232
this.onDisconnect = opt.disconnect;
3333
this.pendingReadCB = null;
@@ -85,7 +85,7 @@ MockBindings.prototype.emitData = function(data) {
8585
};
8686

8787
MockBindings.prototype.disconnect = function(err) {
88-
err = err || new Error('disconnected');
88+
err = err || new Error('Disconnected');
8989
this.onDisconnect(err);
9090
};
9191

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

9898
if (port.openOpt && port.openOpt.lock) {
99-
return cb(new Error('port is locked cannot open'));
99+
return cb(new Error('Port is locked cannot open'));
100100
}
101101

102102
if (this.isOpen) {
103-
return processNextTick(cb, new Error('open: binding is already open'));
103+
return processNextTick(cb, new Error('Open: binding is already open'));
104104
}
105105

106106
port.openOpt = opt;
@@ -118,7 +118,7 @@ MockBindings.prototype.open = function(path, opt, cb) {
118118
MockBindings.prototype.close = function(cb) {
119119
var port = this.port;
120120
if (!port) {
121-
return processNextTick(cb, new Error('port is already closed'));
121+
return processNextTick(cb, new ClosedPortError('close'));
122122
}
123123
processNextTick(function() {
124124
delete port.openOpt;
@@ -134,11 +134,11 @@ MockBindings.prototype.close = function(cb) {
134134

135135
MockBindings.prototype.update = function(opt, cb) {
136136
if (typeof opt !== 'object') {
137-
throw new TypeError('options is not an object');
137+
throw new TypeError('"options" is not an object');
138138
}
139139

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

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

151151
MockBindings.prototype.set = function(opt, cb) {
152152
if (typeof opt !== 'object') {
153-
throw new TypeError('options is not an object');
153+
throw new TypeError('"options" is not an object');
154154
}
155155

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

162162
MockBindings.prototype.write = function(buffer, cb) {
163163
if (!Buffer.isBuffer(buffer)) {
164-
throw new TypeError('buffer is not a Buffer');
164+
throw new TypeError('"buffer" is not a Buffer');
165165
}
166166

167167
if (typeof cb !== 'function') {
168-
throw new TypeError('callback is not a function');
168+
throw new TypeError('"cb" is not a function');
169169
}
170170

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

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

188188
if (!this.isOpen) {

lib/bindings-win32.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ function asyncError(cb, err) {
1010

1111
function WindowsBinding(opt) {
1212
if (typeof opt !== 'object') {
13-
throw new TypeError('options is not an object');
13+
throw new TypeError('"options" is not an object');
1414
}
1515
if (typeof opt.disconnect !== 'function') {
16-
throw new TypeError('options.disconnect is not a function');
16+
throw new TypeError('"options.disconnect" is not a function');
1717
}
1818
this.disconnect = opt.disconnect;
1919
this.fd = null;
@@ -23,15 +23,15 @@ WindowsBinding.prototype.read = require('./read-unix');
2323

2424
WindowsBinding.prototype.open = function(path, options, cb) {
2525
if (typeof path !== 'string') {
26-
throw new TypeError('path is not a string');
26+
throw new TypeError('"path" is not a string');
2727
}
2828

2929
if (typeof options !== 'object') {
30-
throw new TypeError('options is not an object');
30+
throw new TypeError('"options" is not an object');
3131
}
3232

3333
if (typeof cb !== 'function') {
34-
throw new TypeError('cb is not a function');
34+
throw new TypeError('"cb" is not a function');
3535
}
3636

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

5050
WindowsBinding.prototype.close = function(cb) {
5151
if (typeof cb !== 'function') {
52-
throw new TypeError('cb is not a function');
52+
throw new TypeError('"cb" is not a function');
5353
}
5454

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

7373
WindowsBinding.prototype.set = function(options, cb) {
7474
if (typeof options !== 'object') {
75-
throw new TypeError('options is not an object');
75+
throw new TypeError('"options" is not an object');
7676
}
7777

7878
if (typeof cb !== 'function') {
79-
throw new TypeError('cb is not a function');
79+
throw new TypeError('"cb" is not a function');
8080
}
8181

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

8989
WindowsBinding.prototype.write = function(buffer, cb) {
9090
if (!Buffer.isBuffer(buffer)) {
91-
throw new TypeError('buffer is not a Buffer');
91+
throw new TypeError('"buffer" is not a Buffer');
9292
}
9393

9494
if (typeof cb !== 'function') {
95-
throw new TypeError('cb is not a function');
95+
throw new TypeError('"cb" is not a function');
9696
}
9797

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

117117
if (typeof cb !== 'function') {
118-
throw new TypeError('cb is not a function');
118+
throw new TypeError('"cb" is not a function');
119119
}
120120

121121
if (!this.isOpen) {

lib/parser-byte-length.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ function ByteLengthParser(options) {
1111
options = options || {};
1212

1313
if (typeof options.length !== 'number') {
14-
throw new TypeError('length is not a number');
14+
throw new TypeError('"length" is not a number');
1515
}
1616

1717
if (options.length < 1) {
18-
throw new TypeError('length is not greater than 0');
18+
throw new TypeError('"length" is not greater than 0');
1919
}
2020

2121
this.length = options.length;

lib/parser-delimiter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ function DelimiterParser(options) {
2020
options = options || {};
2121

2222
if (options.delimiter === undefined) {
23-
throw new TypeError('delimiter is not a bufferable object');
23+
throw new TypeError('"delimiter" is not a bufferable object');
2424
}
2525

2626
if (options.delimiter.length === 0) {
27-
throw new TypeError('delimiter has a 0 or undefined length');
27+
throw new TypeError('"delimiter" has a 0 or undefined length');
2828
}
2929

3030
this.delimiter = new Buffer(options.delimiter);

lib/push-methods.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ function _read(bytesToRead) {
3939

4040
function pushBindingWrap(opt) {
4141
if (typeof opt.binding !== 'object') {
42-
throw new TypeError('binding is not an object');
42+
throw new TypeError('"binding" is not an object');
4343
}
4444
if (typeof opt.push !== 'function') {
45-
throw new TypeError('push is not a function');
45+
throw new TypeError('"push" is not a function');
4646
}
4747

4848
var binding = opt.binding;

src/read-poller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void ReadPoller::callCallback(int status) {
6666
NAN_METHOD(ReadPoller::New) {
6767
// printf("ReadPoller\n");
6868
if (!info[0]->IsInt32()) {
69-
Nan::ThrowTypeError("First argument must be an fd");
69+
Nan::ThrowTypeError("First argument must be an integer file descriptor");
7070
return;
7171
}
7272

0 commit comments

Comments
 (0)