Skip to content

Commit a3b8d35

Browse files
authored
feat(open): Throw on incorrect baudrate option (#1347)
This was causing a lot of issues, lets make it easier on people.
1 parent c590021 commit a3b8d35

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

examples/socketio/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const serialport = require('serialport');
1818
const SerialPort = serialport.SerialPort;
1919

2020
const serial = new SerialPort('/dev/cu.usbmodem1411', {
21-
baudrate: 9600,
21+
baudRate: 9600,
2222
parser: SerialPort.parsers.byteLength(1)
2323
});
2424

lib/serialport.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ function SerialPort(path, options, callback) {
123123
throw new TypeError(`"path" is not defined: ${path}`);
124124
}
125125

126+
if (settings.baudrate) {
127+
throw new TypeError(`"baudrate" is an unknown option, did you mean "baudRate"?`);
128+
}
129+
126130
if (typeof settings.baudRate !== 'number') {
127131
throw new TypeError(`"baudRate" must be a number: ${settings.baudRate}`);
128132
}

test/serialport.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ describe('SerialPort', () => {
9595
}
9696
});
9797

98+
it('throws an error when given bad baudrate even with a callback', function() {
99+
assert.throws(() => {
100+
this.port = new SerialPort('/dev/exists', { baudrate: 9600 }, () => {});
101+
});
102+
});
103+
98104
it('errors with a non number baudRate', function(done) {
99105
try {
100106
this.port = new SerialPort('/bad/port', { baudRate: 'whatever' });

0 commit comments

Comments
 (0)