johnlemonse / homebridge-telldus

36 stars 22 forks source link

Fix crash of server #18

Closed mifi closed 7 years ago

mifi commented 7 years ago

Implement handling of errors. Today I got an error when homekit was trying to read dimmer value:

0|homebrid | TypeError: Cannot read property 'name' of undefined 0|homebrid | at node-v4.6.0-linux-x64/lib/node_modules/homebridge-telldus/index.js:330:54 0|homebrid | at node-v4.6.0-linux-x64/lib/node_modules/homebridge-telldus/node_modules/telldus-live/telldus-live.js:105:23 0|homebrid | at node-v4.6.0-linux-x64/lib/node_modules/homebridge-telldus/node_modules/telldus-live/telldus-live.js:192:5 0|homebrid | at node-v4.6.0-linux-x64/lib/node_modules/homebridge-telldus/node_modules/telldus-live/telldus-live.js:221:25 0|homebrid | at passBackControl (node-v4.6.0-linux-x64/lib/node_modules/homebridge-telldus/node_modules/oauth/lib/oauth.js:397:13) 0|homebrid | at IncomingMessage. (node-v4.6.0-linux-x64/lib/node_modules/homebridge-telldus/node_modules/oauth/lib/oauth.js:409:9) 0|homebrid | at emitNone (events.js:72:20) 0|homebrid | at IncomingMessage.emit (events.js:166:7) 0|homebrid | at endReadableNT (_stream_readable.js:921:12) 0|homebrid | at nextTickCallbackWith2Args (node.js:442:9) 0|homebrid | at process._tickDomainCallback (node.js:397:17)

Probably network hiccup or Telldus live server problem. This crashed the server. Also make indentation consistent.

mifi commented 7 years ago

I tried unplugging my internet and that caused an internal error inside node-telldus-live, also crashing the server:

0|homebrid | TypeError: Cannot read property 'statusCode' of undefined 0|homebrid | at node-v4.6.0-linux-x64/lib/node_modules/homebridge-telldus/node_modules/telldus-live/telldus-live.js:221:47 0|homebrid | at ClientRequest. (node-v4.6.0-linux-x64/lib/node_modules/homebridge-telldus/node_modules/oauth/lib/oauth.js:421:9) 0|homebrid | at emitOne (events.js:77:13) 0|homebrid | at ClientRequest.emit (events.js:169:7) 0|homebrid | at TLSSocket.socketErrorListener (_http_client.js:269:9) 0|homebrid | at emitOne (events.js:77:13) 0|homebrid | at TLSSocket.emit (events.js:169:7) 0|homebrid | at connectErrorNT (net.js:1012:8) 0|homebrid | at nextTickCallbackWith2Args (node.js:442:9) 0|homebrid | at process._tickDomainCallback (node.js:397:17) PM2 | App [homebridge] with id [0] and pid [2695], exited with code [1] via signal [SIGINT]

This needs to be fixed in node-telldus-live.

I tried mocking error http response from node-telldus-live while running with my fix. The server did not crash, no error printed, and I didn't get an error on my iPhone either, so I'm not quite sure of what happened, but according to this code in node-hap, it will send back a SERVICE_COMMUNICATION_FAILURE to HomeKit in the case of an error in the characteristics callback: https://github.com/KhaosT/HAP-NodeJS/blob/master/lib/Accessory.js#L631