ds18b20 icon indicating copy to clipboard operation
ds18b20 copied to clipboard

try-catch too broad

Open Trikolon opened this issue 9 years ago • 2 comments

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.

Trikolon avatar Apr 18 '16 14:04 Trikolon

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

mlapaglia avatar May 27 '17 03:05 mlapaglia

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

chamerling avatar May 31 '17 08:05 chamerling