timoschlueter / nightscout-librelink-up

Script written in TypeScript that uploads CGM readings from LibreLink Up to Nightscout.
MIT License
192 stars 246 forks source link

TypeError: Cannot read properties of null (reading 'FactoryTimestamp') #30

Closed dassystem closed 2 years ago

dassystem commented 2 years ago

Hi, I have the following issue, right after starting the docker-container. It seems to be connected to nightscout and the librelink cloud correctly.

The error might occure because I have no recent blood glucose values in the libre cloud. (But I plan using it in the future, since I have to switch from libre2 to libre3).

nightscout-libre-link_1  | 
nightscout-libre-link_1  | > nightscout-librelink-up@1.5.0 start
nightscout-libre-link_1  | > node index.js
nightscout-libre-link_1  | 
nightscout-libre-link_1  | 2022-03-18T17:41:04.531Z [info]: Started
nightscout-libre-link_1  | 2022-03-18T17:42:07.692Z [info]: Logged in to LibreLink Up
nightscout-libre-link_1  | 2022-03-18T17:42:15.168Z [info]: Found 1 LibreLink Up connection.
nightscout-libre-link_1  | 2022-03-18T17:42:15.169Z [info]: -> The following connection will be used: XXX (Patient-ID: XXXXXX-XXXX-XXXXX-XXXX-XXXXXXXXXXXX)
nightscout-libre-link_1  | 2022-03-18T17:36:15.329Z [info]: Received blood glucose measurement                     
nightscout-libre-link_1  | /usr/src/app/index.js:186                                                               
nightscout-libre-link_1  |     const measurementDate = getUtcDateFromString(glucoseMeasurement.FactoryTimestamp);  
nightscout-libre-link_1  |                                                                     ^                   
nightscout-libre-link_1  |                                                                                         
nightscout-libre-link_1  | TypeError: Cannot read properties of null (reading 'FactoryTimestamp')                  
nightscout-libre-link_1  |     at uploadToNightscout (/usr/src/app/index.js:186:69)                                
nightscout-libre-link_1  |     at getGlucoseMeasurement (/usr/src/app/index.js:116:9)                              
nightscout-libre-link_1  |     at processTicksAndRejections (node:internal/process/task_queues:96:5)               
nightscout-libre-link_1  |                                                                                         
nightscout-libre-link_1  | Node.js v17.7.1
timoschlueter commented 2 years ago

hi @dassystem, can you make sure you have current measurements in the LibreLink Up app? i have not come across this issue myself yet. :(

dassystem commented 2 years ago

Whether the application has fresh data from a client or not, the server should not crash. Not having data could have several reasons: A fresh setup, missing internet connection of the uploader, issues on the side of Abbots official servers… In these cases, certainly not the whole application should break.

Unfortunately I don't know javascript very well, but I assume that we need to check for null values when loading it to the variable in index.js line 186.

const measurementDate = getUtcDateFromString(glucoseMeasurement.FactoryTimestamp);

An additional try catch might solve it. Happy to test it.

timoschlueter commented 2 years ago

@dassystem is this still an issue with the latest version? I added a few improvements to the error handling.

dassystem commented 2 years ago

Hey @timoschlueter, thanks for the mention!

I'm now getting a error message in the log (which is correct!) and the application is not crashing anymore (which is even better!)

nightscout-libre-link    | 2022-06-14T13:11:48.104457492Z > nightscout-librelink-up@1.7.2 start
nightscout-libre-link    | 2022-06-14T13:11:48.104477066Z > node index.js
nightscout-libre-link    | 2022-06-14T13:20:00.425171582Z [info]: no authTicket.expires
nightscout-libre-link    | 2022-06-14T13:20:00.425530543Z [info]: renew token
nightscout-libre-link    | 2022-06-14T13:20:00.760973318Z [info]: Logged in to LibreLink Up
nightscout-libre-link    | 2022-06-14T13:20:00.954207820Z [info]: Found 1 LibreLink Up connection.
nightscout-libre-link    | 2022-06-14T13:20:00.955213701Z [info]: -> The following connection will be used: <MY-NAME> (Patient-ID: <MY-UUID>)
nightscout-libre-link    | 2022-06-14T13:20:01.130118050Z [info]: Received blood glucose measurement items
nightscout-libre-link    | 2022-06-14T13:20:01.132070664Z [error]: Error getting glucose measurements Cannot read properties of null (reading 'FactoryTimestamp')

So at least this unhappy-path is working as expected and this bug issue can be closed. Thank you!

timoschlueter commented 2 years ago

awesome! :)