Skip to content

Commit 762c52a

Browse files
committed
error handling. handle differing outputs.
1 parent ddaf672 commit 762c52a

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

bin/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
#!/usr/bin/env node
22

3+
import * as Promise from 'bluebird';
4+
5+
function onError (e) {
6+
console.log('uncaught error', e);
7+
}
8+
9+
Promise.onPossiblyUnhandledRejection(onError)
10+
process.on('uncaughtException', onError);
11+
312
import program = require('commander');
413
import { InterfaceGlobal, InterfaceCLI } from '../lib/interface';
514

lib/command-poll.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as table from 'table';
66
import { ensureObdIsConnected } from './connection';
77

88
export default function (pids:string[]) {
9-
Promise.map(pids, (pidCodeOrName) => {
9+
Promise.mapSeries(pids, (pidCodeOrName) => {
1010
return util.getPidByCode(pidCodeOrName) || util.getPidByName(pidCodeOrName);
1111
})
1212
.then((pids) => poll(pids));
@@ -15,7 +15,7 @@ export default function (pids:string[]) {
1515
function poll (pids:OBD.PIDS.PID[]) {
1616
return ensureObdIsConnected()
1717
.then(() => {
18-
return Promise.map(pids, (p) => {
18+
return Promise.mapSeries(pids, (p) => {
1919
const poller:OBD.ECUPoller = new OBD.ECUPoller({
2020
pid: p,
2121
interval: null
@@ -33,11 +33,14 @@ function poll (pids:OBD.PIDS.PID[]) {
3333

3434
pollReults.forEach((p) => {
3535
// This will always be a string for us so we can cast it
36-
data.push([<string>p.name, p.value.toFixed(2)]);
36+
data.push([<string>p.name, p.value && p.value.toFixed ? p.value.toFixed(2) : p.value]);
3737
});
3838

3939
console.log(table.table(data, {
4040
border: table.getBorderCharacters('norc')
4141
}));
42+
})
43+
.catch((e) => {
44+
console.log(e);
4245
});
4346
}

lib/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ export function getPidByCode (code: string):OBD.PIDS.PID {
2828

2929
export function getPidByName (name: string):OBD.PIDS.PID {
3030
return _.find(getPidInstances(), (p:OBD.PIDS.PID) => {
31-
return p.getName() === name;
31+
return p.getName().toUpperCase() === name.toUpperCase();
3232
});
3333
}

0 commit comments

Comments
 (0)