momenso / node-dht-sensor

Node.js Humidity and Temperature sensor addon
GNU Lesser General Public License v3.0
309 stars 72 forks source link

ReadWorker mode doesn't catch exceptions on init #103

Closed ashleybaldock closed 4 years ago

ashleybaldock commented 5 years ago

Using the Promises version of the API, any issues during initialisation aren't caught and surfaced as JS exceptions - this leads to the app using the lib crashing without being able to handle the error (e.g. in the case where you don't have a device attached...

bcm2835_init: Unable to open /dev/gpiomem: No such file or directory
[nodemon] app crashed - waiting for file changes before starting...

From taking a look at node-dht-sensor.cpp this looks like a simple case of the Execute override not checking for initialized == true before running Read(), so it attempts to read regardless of whether init was successful.

This makes the promise version of the call unusable IMO since there's no way to deal with initialisation errors. Using the synchronous version works as expected.

momenso commented 5 years ago

This improvement to the promise API would be very welcome. Do you have a PR in the works?