Isaksson / node-red-contrib-unifi

MIT License
52 stars 20 forks source link

Install from NodeRED palette crashes the NodeRED server, type error #31

Closed bcd1983 closed 4 years ago

bcd1983 commented 4 years ago

It appears there is a type error in unifi.js. When I install the node-red-contrib-unifi package (latest version of NodeRED and the package), it immediately crashes.

Upon further investigation, you can fix this by casting to a String before calling the toLowerCase() function.

9 May 00:36:49 - TypeError: command.toLowerCase is not a function at controller.login (/data/node_modules/node-red-contrib-unifi/unifi.js:43:32)

i.e.

String(msg.payload.command).toLowerCase(); switch(String(command).toLowerCase())

This solved the issue for me locally.

Isaksson commented 4 years ago

Could it be that you run NodeRED on a MAC? I have seen this issue before for some users but only on MAC not on any other operation systems.

Isaksson commented 4 years ago

Are you sure that you pass a string to the msg.payload.command? I could get the same error message (still dont crash node-red) if i pass an bool instead of string. msg.payload = { command: true}; msg.payload = { command: "true"}; the example is just a test and will give you the no command error on the node.

Isaksson commented 4 years ago

Even if you send command in int or bool it will now be converted to string.

coza73 commented 4 years ago

I got that error (and crash) when I was not passing the message properly. Probably should not crash but....

I was trying to send the message using a trigger node but never got it working. As soon as I passed for example

msg.payload = { command: "ClientDevices"}; return msg;

from a function node it worked fine.

Isaksson commented 4 years ago

Yes, true, it should not crash, but the new version will handle it even if the command not is sent as string.