chamerling / ds18b20

Get temperature from ds18b20 sensors connected to Raspberry PI
36 stars 19 forks source link

try-catch too broad #9

Open Trikolon opened 8 years ago

Trikolon commented 8 years ago

The try-catch block in function temperature() covers its callback. This way the library catches all exceptions thrown in the callback, even unrelated ones from applications using the library, and causes it to fail.

https://github.com/chamerling/ds18b20/blob/6a8e71af54feea22edcac9945a38e615525d40da/lib/ds18b20.js#L85

Example:

ds18b20.temperature(id, (error, value) => {
    throw new Error("Custom error unrelated to ds18b20");
}

Output: ERROR: Can not read temperature for sensor XY

The try-catch block should only catch exceptions from parseData() instead.

mlapaglia commented 7 years ago

The PR for this bug fixed the same issue for me.

chamerling commented 7 years ago

Going to take some time to check this and refactor the module. Thx for the reminder here ;)