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.
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.
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 aNot connected to MSFS
error.