Add Exception handling when processing udev devices (#5088)

* Add Exception handling to UDEV reading and parsing

Khadas VIM4 UDEV returns something that python crapps its pants about. The exception just allows it to continue.

* Add an exception print

Added an exception print for the times things go bad.

* Split exception handling

The exception is not fatal when parsing error happens on one node. print it and continue.

* cleanups

* swapped functions

device.device_node   function bails very badly!  It raises no exceptions to the top but complains and errors

* Update supervisor/hardware/manager.py

Co-authored-by: Stefan Agner <stefan@agner.ch>

* Update supervisor/hardware/manager.py

---------

Co-authored-by: Stefan Agner <stefan@agner.ch>
Co-authored-by: Pascal Vizeli <pvizeli@syshack.ch>
This commit is contained in:
Richard P 2024-05-29 20:33:15 +01:00 committed by GitHub
parent 974c882b9a
commit 5f5754e860
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -103,7 +103,13 @@ class HardwareManager(CoreSysAttributes):
# Exctract all devices
for device in self._udev.list_devices():
# Skip devices without mapping
if not device.device_node or self.helper.hide_virtual_device(device):
try:
if not device.device_node or self.helper.hide_virtual_device(device):
continue
except UnicodeDecodeError as err:
# Some udev properties have an unkown/different encoding. This is a general
# problem with pyudev, see https://github.com/pyudev/pyudev/pull/230
_LOGGER.warning("Ignoring udev device due to error: %s", err)
continue
self._devices[device.sys_name] = Device.import_udev(device)