Koenkk / zigbee2mqtt

Zigbee 🐝 to MQTT bridge 🌉, get rid of your proprietary Zigbee bridges 🔨
https://www.zigbee2mqtt.io
GNU General Public License v3.0
11.71k stars 1.64k forks source link

Unhandled exception when payload is `null` #3980

Closed dvv closed 4 years ago

dvv commented 4 years ago

Bug Report

What happened

On zigbee2mqtt startup my "ZNCZ02LM - Xiaomi Mi power plug ZigBee" caused:

Jul 26 15:50:48 orange node[8109]: (node:8109) UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object
Jul 26 15:50:48 orange node[8109]:     at Function.entries (<anonymous>)
Jul 26 15:50:48 orange node[8109]:     at Controller.iteratePayloadAttributeOutput (/myhome/service/zigbee2mqtt/node_modules/zigbee2mqtt/lib/controller.js:335:43)
Jul 26 15:50:48 orange node[8109]:     at Controller.iteratePayloadAttributeOutput (/myhome/service/zigbee2mqtt/node_modules/zigbee2mqtt/lib/controller.js:348:29)
Jul 26 15:50:48 orange node[8109]:     at processTicksAndRejections (internal/process/task_queues.js:93:5)
Jul 26 15:50:48 orange node[8109]:     at async Controller.publishEntityState (/myhome/service/zigbee2mqtt/node_modules/zigbee2mqtt/lib/controller.js:325:21)
Jul 26 15:50:48 orange node[8109]: (Use `node --trace-warnings ...` to show where the warning was created)
Jul 26 15:50:48 orange node[8109]: (node:8109) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
Jul 26 15:50:48 orange node[8109]: (node:8109) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

If it does matter the device voltage attribute is null.

What did you expect to happen

Skip such payload plus (optional?) warning.

How to reproduce it (minimal and precise)

The bug is here -- null still is an object.

typeof(null) === "object"

Debug Info

Zigbee2mqtt version: Adapter hardware: CC2531, CC2530, CC26X2R1 or CC1352P-2 Adapter firmware version:

Koenkk commented 4 years ago

Fixed!

Changes will be available in the latest dev branch in a few hours (https://www.zigbee2mqtt.io/how_tos/how-to-switch-to-dev-branch.html)