Skip to content
Merged
Prev Previous commit
Next Next commit
catch exception in ICS find devices
  • Loading branch information
felixdivo committed Jun 29, 2018
commit 9621a29e4ea80b97412d730970099d4ad84785b0
10 changes: 7 additions & 3 deletions can/interfaces/ics_neovi/neovi_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ def _detect_available_configs():
if ics is None:
return []
# TODO: add the channel(s)
return [{
'serial': NeoViBus.get_serial_number(device)
} for device in ics.find_devices()]
try:
return [{
'serial': NeoViBus.get_serial_number(device)
} for device in ics.find_devices()]
except Exception as e:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this try/for should be inverted - if the try was around each call to get_serial_number then any working devices can be returned?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the code a bit clearer to show that only the call to ics.find_devices() is wrapped in a try-catch clause. The method NeoViBus.get_serial_number() itself should never fail.

logger.debug("Failed to detect configs: %s", e)
return []

def _find_device(self, type_filter=None, serial=None):
if type_filter is not None:
Expand Down