master/worker_db: rethrow DeviceError exception with device name on device creation failure. Closes #396

This commit is contained in:
Sebastien Bourdeauducq 2016-04-16 19:55:08 +08:00
parent caf774579a
commit b74aa12351
1 changed files with 14 additions and 1 deletions

View File

@ -112,6 +112,10 @@ def _create_device(desc, device_mgr):
raise ValueError("Unsupported type in device DB: " + ty) raise ValueError("Unsupported type in device DB: " + ty)
class DeviceError(Exception):
pass
class DeviceManager: class DeviceManager:
"""Handles creation and destruction of local device drivers and controller """Handles creation and destruction of local device drivers and controller
RPC clients.""" RPC clients."""
@ -141,7 +145,16 @@ class DeviceManager:
if name in self.active_devices: if name in self.active_devices:
return self.active_devices[name] return self.active_devices[name]
else: else:
dev = _create_device(self.get_desc(name), self) try:
desc = self.get_desc(name)
except Exception as e:
raise DeviceError("Failed to get description of device '{}'"
.format(name)) from e
try:
dev = _create_device(desc, self)
except Exception as e:
raise DeviceError("Failed to create device '{}'"
.format(name)) from e
self.active_devices[name] = dev self.active_devices[name] = dev
return dev return dev