bahamas10 / hue-cli

A command line interface to phillips hue
http://bahamas10.github.com/hue-cli/
221 stars 24 forks source link

Cryptic error message after hue bridge configuration changes #28

Open terracotta004 opened 6 years ago

terracotta004 commented 6 years ago

Recently I was running into this bizarre error whenever I ran anything to do with hue lights (e.g. hue lights on, hue lights off, etc.) on node v9.3.0, npm 5.6.0, & hue-cli 0.3.1.

I was about to ask for help here, but then I realized that the IP of my hue bridge changed, which may or may not have been the root of the problem. After re-registering hue-cli with the new configuration everything started working again. However, this original error message was pretty unhelpful in indicating that this might have been the problem. It could have been that the old IP was given to a different device on the local network and hue-cli was getting bogus data from it.

I'd suggest that this part of the code be adjusted so that, if the configuration stops working for some reason, it gives a more helpful error message stating something has changed with the connection, instead of leaving the user to scratch their head in confusion.


C:\Users\Ben\AppData\Roaming\npm\node_modules\hue-cli\hue-cli.js:141
      var keys = Object.keys(lights);
                        ^

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at C:\Users\Ben\AppData\Roaming\npm\node_modules\hue-cli\hue-cli.js:141:25
    at Request.<anonymous> (C:\Users\Ben\AppData\Roaming\npm\node_modules\hue-cli\hue-cli.js:342:5)
    at Request._callback (C:\Users\Ben\AppData\Roaming\npm\node_modules\hue-cli\node_modules\hue.js\lib\Hue.js:36:43)
    at Request.self.callback (C:\Users\Ben\AppData\Roaming\npm\node_modules\hue-cli\node_modules\request\main.js:122:22)    at Request.emit (events.js:159:13)
    at Request.<anonymous> (C:\Users\Ben\AppData\Roaming\npm\node_modules\hue-cli\node_modules\request\main.js:661:16)
    at Request.emit (events.js:164:20)
    at IncomingMessage.<anonymous> (C:\Users\Ben\AppData\Roaming\npm\node_modules\hue-cli\node_modules\request\main.js:623:14)
    at IncomingMessage.emit (events.js:164:20)
bahamas10 commented 6 years ago

ah, that's a really ugly message.

I just tried this manually and am able to reproduce it. If a server is running on port 80 that is not hue, the hue.js library hue-cli uses unfortunately will not trigger an error. If you look at that repo it's painfully out of date, and I even have a PR that was never addressed.

Instead, I'd recommend you take a look at huadm. This is the spiritual successor to hue-cli with far more options and robust error handling. Running the same test on hueadm, first using a host not running a server on port 80, and second using a host running a file server on port 80, has the following results.

$ ./bin/hueadm -H 10.0.1.1 -U foo lights
error: Error: connect ECONNREFUSED 10.0.1.1:80
$ ./bin/hueadm -H localhost -U foo lights
error: Error: bad statusCode 404