nightscout / nightscout-connect

Single entry point for bridging cloud resources containing diabetes data to Nightscout.
GNU Affero General Public License v3.0
31 stars 33 forks source link

fix: Fixing Libre Linkup Crash #34

Open billyjbryant opened 8 months ago

billyjbryant commented 8 months ago

Description

When the connect plugin pulls data for Libre LinkUp, if last_known is null, the plugin crashes with the following error, causing a reboot loop on the container:

 /opt/app/node_modules/nightscout-connect/lib/sources/librelinkup.js:124
       var last_updated = last_known.entries;
                                     ^

 TypeError: Cannot read properties of null (reading 'entries')
     at Object.transformGlucose [as transformer] (/opt/app/node_modules/nightscout-connect/lib/sources/librelinkup.js:124:37)
     at transformService (/opt/app/node_modules/nightscout-connect/lib/machines/fetch.js:14:37)
     at Interpreter._exec (/opt/app/node_modules/xstate/lib/interpreter.js:269:63)
     at Interpreter.exec (/opt/app/node_modules/xstate/lib/interpreter.js:1026:10)
     at Interpreter.execute (/opt/app/node_modules/xstate/lib/interpreter.js:387:14)
     at Interpreter.update (/opt/app/node_modules/xstate/lib/interpreter.js:415:12)
     at /opt/app/node_modules/xstate/lib/interpreter.js:110:15
     at Scheduler.process (/opt/app/node_modules/xstate/lib/scheduler.js:69:7)
     at Scheduler.schedule (/opt/app/node_modules/xstate/lib/scheduler.js:48:10)
     at Interpreter.send (/opt/app/node_modules/xstate/lib/interpreter.js:104:23)

This is fixed by adding in appropriate checks to ensure that direct reference to an undefined var are not performed and thus prevents the system from crashing.

fixes: #27

billyjbryant commented 7 months ago

Is anyone going to review this? It has been in for 6 weeks with no review or comment.

AndyLow91 commented 7 months ago

Definitely safe to merge this, the var last_updated doesn't appear to be used at all throughout the rest of the script. In any case adding the ternary operator makes perfect sense.

This line may not even be needed, or it may for some future plans.

Just to be safe, I have also tested with this updated and confirmed working, although I couldn't recreate the problem locally either way, i can see that this could cause the problem stated.

@bewest approval is required to merge.