Skip to content

Commit

Permalink
Remove CanBridgeInitializationError custom error
Browse files Browse the repository at this point in the history
It just made it harder to get the actual error and actual stack trace.
  • Loading branch information
qwertychouskie committed Aug 22, 2024
1 parent a0152c2 commit 0ef46b6
Showing 1 changed file with 24 additions and 37 deletions.
61 changes: 24 additions & 37 deletions lib/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ export enum ThreadPriority {
PriorityError
}

export class CanBridgeInitializationError extends Error {
cause: any;

constructor(cause: any) {
super("Failed to load the CANBridge native addon. This is likely a packaging problem, or perhaps the Visual Studio C++ redistributable package is not installed. See cause field for details.");
this.cause = cause;
}
}

export class CanBridge {
getDevices: () => Promise<CanDeviceInfo[]>;
registerDeviceToHAL: (descriptor:string, messageId:Number, messageMask:number) => number;
Expand All @@ -67,34 +58,30 @@ export class CanBridge {
ackHeartbeats: () => void;

constructor() {
try {
const addon = require('node-gyp-build')(path.join(__dirname, '..'));

this.getDevices = promisify(addon.getDevices);
this.registerDeviceToHAL = addon.registerDeviceToHAL;
this.unregisterDeviceFromHAL = promisify(addon.unregisterDeviceFromHAL);
this.receiveMessage = addon.receiveMessage;
this.openStreamSession = addon.openStreamSession;
this.readStreamSession = addon.readStreamSession;
this.closeStreamSession = addon.closeStreamSession;
this.getCANDetailStatus = addon.getCANDetailStatus;
this.sendCANMessage = addon.sendCANMessage;
this.sendHALMessage = addon.sendHALMessage;
this.initializeNotifier = addon.initializeNotifier;
this.waitForNotifierAlarm = promisify(addon.waitForNotifierAlarm);
this.stopNotifier = addon.stopNotifier;
this.writeDfuToBin = promisify(addon.writeDfuToBin);
this.openHALStreamSession = addon.openHALStreamSession;
this.readHALStreamSession = addon.readHALStreamSession;
this.closeHALStreamSession = addon.closeHALStreamSession;
this.setThreadPriority = addon.setThreadPriority;
this.setSparkMaxHeartbeatData = addon.setSparkMaxHeartbeatData;
this.startRevCommonHeartbeat = addon.startRevCommonHeartbeat;
this.ackHeartbeats = addon.ackHeartbeats;
this.stopHeartbeats = addon.stopHeartbeats;
} catch (e: any) {
throw new CanBridgeInitializationError(e);
}
const addon = require('node-gyp-build')(path.join(__dirname, '..'));

this.getDevices = promisify(addon.getDevices);
this.registerDeviceToHAL = addon.registerDeviceToHAL;
this.unregisterDeviceFromHAL = promisify(addon.unregisterDeviceFromHAL);
this.receiveMessage = addon.receiveMessage;
this.openStreamSession = addon.openStreamSession;
this.readStreamSession = addon.readStreamSession;
this.closeStreamSession = addon.closeStreamSession;
this.getCANDetailStatus = addon.getCANDetailStatus;
this.sendCANMessage = addon.sendCANMessage;
this.sendHALMessage = addon.sendHALMessage;
this.initializeNotifier = addon.initializeNotifier;
this.waitForNotifierAlarm = promisify(addon.waitForNotifierAlarm);
this.stopNotifier = addon.stopNotifier;
this.writeDfuToBin = promisify(addon.writeDfuToBin);
this.openHALStreamSession = addon.openHALStreamSession;
this.readHALStreamSession = addon.readHALStreamSession;
this.closeHALStreamSession = addon.closeHALStreamSession;
this.setThreadPriority = addon.setThreadPriority;
this.setSparkMaxHeartbeatData = addon.setSparkMaxHeartbeatData;
this.startRevCommonHeartbeat = addon.startRevCommonHeartbeat;
this.ackHeartbeats = addon.ackHeartbeats;
this.stopHeartbeats = addon.stopHeartbeats;
}
}

Expand Down

0 comments on commit 0ef46b6

Please sign in to comment.