Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on empty nightscout instance (glooko) #9

Open
burnedikt opened this issue Jul 10, 2023 · 5 comments
Open

Error on empty nightscout instance (glooko) #9

burnedikt opened this issue Jul 10, 2023 · 5 comments

Comments

@burnedikt
Copy link

The following code throws an error if running the connect plugin with glooko credentials on an empty nightscout instance, I assume because there is no last_known yet.

/opt/app/node_modules/nightscout-connect/lib/sources/glooko/index.js:85
      var last_mills = Math.max(two_days_ago, last_known.entries ? last_known.entries.getTime( ) : two_days_ago);
                                                         ^
TypeError: Cannot read properties of null (reading 'entries')
    at Object.dataFromSesssion (/opt/app/node_modules/nightscout-connect/lib/sources/glooko/index.js:85:58)
    at dataFetchService (/opt/app/node_modules/nightscout-connect/lib/machines/fetch.js:8:19)
    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)

https://github.com/nightscout/nightscout-connect/blob/8f2ab374a288f8541b916d92cecfb55bb5f44889/lib/sources/glooko/index.js#L85C22-L85C22

@burnedikt
Copy link
Author

Actually, I also get this issue when there are entries on nightscout already. I'm having a hard time to pin this down due to the "machines" architecture, but I guess this means the DetermineGaps step doesn't determine any gap.

Solution is probably just a different check à la

- var last_mills = Math.max(two_days_ago, last_known.entries ? last_known.entries.getTime( ) : two_days_ago);
+ var last_mills = Math.max(two_days_ago, last_known && last_known.entries ? last_known.entries.getTime( ) : two_days_ago);

But it seems odd that last_known stays null since it should always return something here?

return Promise.resolve({ sgvs: null, treatments: null, profile: null, devicestatus: null });
.

Logs leading up until the NPE btw:

nightscout  | GAP FOR
nightscout  | WAITING FOR data-processed
nightscout  | ALARM SOCKET: emitted clear_alarm to all clients
nightscout  | tick 2023-07-11T08:33:01.117Z
nightscout  | DEBUG nightscout-connect {
nightscout  |   now: 2023-07-11T08:33:01.117Z,
nightscout  |   type: 'heartbeat',
nightscout  |   sig: 'internal://heartbeat/1',
nightscout  |   beat: 1,
nightscout  |   interval: 60000,
nightscout  |   started: 2023-07-11T08:32:01.115Z
nightscout  | }
nightscout  | Load Complete:
nightscout  |    profiles:1
nightscout  | data loaded: reloading sandbox data and updating plugins
nightscout  | EVENTUALLY FOUND null
nightscout  | /opt/app/node_modules/nightscout-connect/lib/sources/glooko/index.js:85
nightscout  |       var last_mills = Math.max(two_days_ago, last_known.entries ? last_known.entries.getTime( ) : two_days_ago);

@bewest
Copy link
Member

bewest commented Jul 11, 2023

Yes, I think Sulka has some patches that help with this. last_known.entries and friends should be a date object or may be null. Apologies for this!

@bewest
Copy link
Member

bewest commented Aug 6, 2023

Glooko patches from Sulka have been integrated and released. Hope this helps!

@burnedikt
Copy link
Author

Will check, thanks 🙏

@burnedikt
Copy link
Author

Seems like this still happens with the latest version (0.10.0) of nightscout-connect:

EVENTUALLY FOUND null
(node:39418) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'entries' of null
    at Object.dataFromSesssion (/cgm-remote-monitor/node_modules/nightscout-connect/lib/sources/glooko/index.js:85:58)
    at dataFetchService (/cgm-remote-monitor/node_modules/nightscout-connect/lib/machines/fetch.js:8:19)
    at Interpreter._exec (/cgm-remote-monitor/node_modules/xstate/lib/interpreter.js:269:63)
    at Interpreter.exec (/cgm-remote-monitor/node_modules/xstate/lib/interpreter.js:1026:10)
    at Interpreter.execute (/cgm-remote-monitor/node_modules/xstate/lib/interpreter.js:387:14)
    at Interpreter.update (/cgm-remote-monitor/node_modules/xstate/lib/interpreter.js:415:12)
    at /cgm-remote-monitor/node_modules/xstate/lib/interpreter.js:110:15
    at Scheduler.process (/cgm-remote-monitor/node_modules/xstate/lib/scheduler.js:69:7)
    at Scheduler.schedule (/cgm-remote-monitor/node_modules/xstate/lib/scheduler.js:48:10)
    at Interpreter.send (/cgm-remote-monitor/node_modules/xstate/lib/interpreter.js:104:23)
    at _a.id (/cgm-remote-monitor/node_modules/xstate/lib/interpreter.js:1139:15)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants