Skip to content

Commit

Permalink
Error handling
Browse files Browse the repository at this point in the history
Added try/catch to a number of internal functions when calling zigbee-herdsman or zigbee-herdsman-converters functions
  • Loading branch information
asgothian committed Jan 11, 2025
1 parent c1eb64f commit 67304dc
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 135 deletions.
2 changes: 1 addition & 1 deletion lib/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class Binding {
await this.doBindUnbind(type, bind_source, bind_source_ep, 'coordinator', '1');
this.debug('Successfully ' + (type === 'bind' ? 'bound' : 'unbound') + ' Coordinator from ' + bind_source);
} catch (e) {
this.error(`Could not ${type} Coordinator from ${bind_source}: ${JSON.stringify(e)}`);
this.error(`Could not ${type} Coordinator from ${bind_source}: ${(e && e.message ? e.message : 'no error message')} ${(e && e.stack ? e.stack : 'no call stack')}`);
}
}
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions lib/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ class Groups {
for (const gpid of groups[epid]) {
const gpidn = parseInt(gpid);
if (gpidn < 0) {
this.warn(`calling removeDevFromGroup with ${sysid}, ${-gpidn}, ${epid}` );
this.debug(`calling removeDevFromGroup with ${sysid}, ${-gpidn}, ${epid}` );
const response = await this.zbController.removeDevFromGroup(sysid, (-gpidn), epid);
if (response && response.error) {
errors.push(response.error);
this.error(`remove dev from group Error: ${JSON.stringify(response.error)}`);
}

} else if (gpidn > 0) {
this.warn(`calling addDevToGroup with ${sysid}, ${gpidn}, ${epid}` );
this.debug(`calling addDevToGroup with ${sysid}, ${gpidn}, ${epid}` );
const response = await this.zbController.addDevToGroup(sysid, (gpidn), epid);
if (response && response.error) {
errors.push(response.error);
Expand All @@ -158,7 +158,7 @@ class Groups {
}
}
} catch (e) {
this.warn('caught error ' + JSON.stringify(e) + ' in updateGroupMembership');
this.warn('caught error ' + (e && e.message ? e.message : 'no error message') + ' in updateGroupMembership');
this.adapter.sendTo(from, command, {error: e}, callback);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/zbDeviceAvailability.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class DeviceAvailability extends BaseExtension {
}
} catch (error) {
this.sendError(error);
this.debug(`Exception in readState of '${device.ieeeAddr}' - error : '${error}'`);
this.debug(`Exception in readState of '${device.ieeeAddr}' - error : '${(error && error.message ? error.message : 'no error message')}'`);
// intentionally empty: Just present to ensure we cause no harm
// when reading the state fails. => fall back on standard Ping function
}
Expand Down
Loading

0 comments on commit 67304dc

Please sign in to comment.