dehsgr / node-red-contrib-evohome

This provides nodes for controlling Honeywell Evohome
ISC License
5 stars 7 forks source link

TypeError: session.getLocations is not a function #15

Closed psy0rz closed 2 years ago

psy0rz commented 2 years ago

Probably related to #1 and the 1.1.1 fix you just uploaded?

My nodered keeps crashing when it tries to get the temperature:

Feb  2 18:22:23 nodered Node-RED[37034]: 2 Feb 18:22:23 - [red] Uncaught Exception:
Feb  2 18:22:23 nodered Node-RED[37034]: 2 Feb 18:22:23 - [error] TypeError: session.getLocations is not a function
Feb  2 18:22:23 nodered Node-RED[37034]:     at publishEvohomeStatus (/home/nodered/.node-red/node_modules/node-red-contrib-evohome/evohome/evohome-status.js:26:22)
Feb  2 18:22:23 nodered Node-RED[37034]:     at Timeout._onTimeout (/home/nodered/.node-red/node_modules/node-red-contrib-evohome/evohome/evohome-status.js:71:5)
Feb  2 18:22:23 nodered Node-RED[37034]:     at listOnTimeout (internal/timers.js:557:17)
Feb  2 18:22:23 nodered Node-RED[37034]:     at processTimers (internal/timers.js:500:7)
Feb  2 18:22:23 nodered systemd[1]: nodered.service: Main process exited, code=exited, status=1/FAILURE
psy0rz commented 2 years ago

it never worked correctly, so 1.1.1 didnt actually break it, but i hoped it would fix it :)

psy0rz commented 2 years ago

strange: I've deleted the evohome session, which then became "[object Object]" and now it works!

Also: why does node-red crash if a module isnt handling an exception? shouldn't be there some kind of global exception handler that catches everything a module throws?

realgnark commented 2 years ago

i also just ran into the issue.

the cause seems as follows.

globalContext object is serialized to disk (at least in my configuration) while node-red is stopped/started/restarted.

unfortunately that context within evohome-session holds functions and potentially other stuff that cannot go to JSON and back, especially its prototype structure. so while the nodes wake up after a restart of node-red the globalContext.get("evohome-session") returns an object that "seems" to be as expected but in fact is not and session.getLocations() is of course gone. this seems to be fixable alone by deleting the evohome-session from global context. i still dont know if removing that during runtime is safe or if a restart should also be done after that.

one possibility to fix the issue would of course be to ask in evohome-status.js not only

if (!globalContext.get('evohome-session')) {

but instead

if (!globalContext.get('evohome-session') || !globalContext.get('evohome-session').getLocations || !globalContext.get('evohome-session').getLocations.apply) {

in order to "start with a new session object from scratch" including all constructors and prototype hierarchy.

but i am sure the problem would probably be better fixed by not storing implementation in session objects that in my opinion are designed to only hold data.

i observed situations where node-red complains about getLocations(). i also observed node-red to crash entirely and needs to be started in safe mode in order to remove the broken session from global context. i can only guess that in this case the missing functions or prototype members cause errors so deep inside red-matic that it decides to simply stop.

realgnark commented 2 years ago

ok i fixed it for me in the two places:

evohome-status.js line 15 replaced with: if (!globalContext.get('evohome-session') || !globalContext.get('evohome-session').getLocations) {

evohome-control.js line 12 inserted: if (!session.getLocations) session = null;

this fix is not a beauty but now i can restart node-red and use evohome-status (evohome-control i did NOT test) without exceptions or crashes...

dehsgr commented 2 years ago

@realgnark can you try current source and if it solves your issue? If you confirm fix works I'll publish new NPM package ASAP. Thank you!

realgnark commented 2 years ago

ok i ll give it a try. unfortunately currently i have to manually copy over stuff back and forth. so a code review showed you

realgnark commented 2 years ago

tested everything and it works exactly as expected :)

dehsgr commented 2 years ago

Published new version to NPM. Thank you for verifying.