Pomax / msfs-simconnect-api-wrapper

A JavaScripty wrapper around node-simconnect
Other
14 stars 6 forks source link

Define the behaviour when MSFS is not connected #19

Closed Pomax closed 1 year ago

Pomax commented 1 year ago

I ran into a situation where I was testing some code that, I thought, did not need to query MSFS, but instead crashed out because there was a "sanity check" api call that was allowed through, despite there not being an MSFS connection.

file:///C:/Users/Pomax/Documents/Git/projects/are-we-flying/node_modules/msfs-simconnect-api-wrapper/msfs-api.js:228
      handle.addToDataDefinition(
             ^

TypeError: Cannot read properties of undefined (reading 'addToDataDefinition')
    at file:///C:/Users/Pomax/Documents/Git/projects/are-we-flying/node_modules/msfs-simconnect-api-wrapper/msfs-api.js:228:14
    at Array.forEach (<anonymous>)
    at MSFS_API.addDataDefinitions (file:///C:/Users/Pomax/Documents/Git/projects/are-we-flying/node_modules/msfs-simconnect-api-wrapper/msfs-api.js:221:15)
    at MSFS_API.get (file:///C:/Users/Pomax/Documents/Git/projects/are-we-flying/node_modules/msfs-simconnect-api-wrapper/msfs-api.js:299:10)
    at AutoPilot.get (file:///C:/Users/Pomax/Documents/Git/projects/are-we-flying/src/api/autopilot/autopilot.js:152:21)
    at AutoPilot.revalidateFlight (file:///C:/Users/Pomax/Documents/Git/projects/are-we-flying/src/api/autopilot/autopilot.js:132:71)
    at AutopilotRouter.revalidateWaypoints (file:///C:/Users/Pomax/Documents/Git/projects/are-we-flying/src/classes/server/autopilot-router.js:60:21)
    at UpgradedSocket.router (file:///C:/Users/Pomax/Documents/Git/projects/are-we-flying/node_modules/socketless/src/upgraded-socket.js:247:49)
    at UpgradedSocket.emit (node:events:512:28)
    at Receiver.receiverOnMessage (C:\Users\Pomax\Documents\Git\projects\are-we-flying\node_modules\ws\lib\websocket.js:1192:20)

Node.js v19.8.1

Both the handle itself, and the MSFS .connected flag can be used to prevent this, so the external API functions should probably be made conditional on either, and throwing a Not connected to MSFS error.

Pomax commented 1 year ago

fixed in https://github.com/Pomax/msfs-simconnect-api-wrapper/commit/7a96dff9e5d0de53035bf23c9b86a4c0259cec2c