Foddy / node-red-contrib-huemagic

Philips Hue node to control bridges, lights, groups, motion sensors, temperature sensors and Lux sensors using Node-RED.
https://flows.nodered.org/node/node-red-contrib-huemagic
Apache License 2.0
201 stars 66 forks source link

TypeError: Cannot create property 'results' on boolean 'false' #366

Open Wombosvideo opened 2 years ago

Wombosvideo commented 2 years ago

Describe the bug When Hue Magic is installed Node-RED just boot-loops. This means it boots up to a certain point where it hits the given TypeError and then restarts until it crashes again at the same point. This continues forever. It makes using Node-RED unusable.

Expected behavior Node-RED and Hue Magic load normally and boot succeeds without any issues.

Error message

27 Apr 17:13:00 - [red] Uncaught Exception:
27 Apr 17:13:00 - [error] TypeError: Cannot create property 'results' on boolean 'false'
    at /home/nodered/.node-red/node_modules/node-red-contrib-huemagic/huemagic/hue-bridge.js:185:32
    at runNextTicks (node:internal/process/task_queues:60:5)
    at process.processImmediate (node:internal/timers:442:9)
nodered.service: Main process exited, code=exited, status=1/FAILURE

Quick fix Add the following line to ~/.node-red/node_modules/node-red-contrib-huemagic/huemagic/hue-bridge.js:

...
// GET BRIDGE INFORMATION
scope.getBridgeInformation()
.then(function(bridgeInformation))
{
    if(typeof bridgeInformation == 'boolean') { return; } // <-- This line

    // START TOUCHLINK
    ...

This will return both Node-RED and Hue Magic to their desired functionality, without any drawbacks for me so far.

Please complete the following information:

Additional context The problem only occured after an update of the module. Before, I hit the issue #350 which is why I decided to restart Node-RED. Now I can't use Node-RED at all.

ptweety commented 2 years ago

Hi @Wombosvideo, you can try a downgrade to node v16.x

Wombosvideo commented 2 years ago

Issue also confirmed on Node.js v16.14.2

Wombosvideo commented 2 years ago

So far my provided quick fix seems to be doing to job just fine as the problems probably occur due to requests made before the data is available (i.e. before Hue Magic connects to the bridge)