Skip to content

Commit 8ec925a

Browse files
committed
tango command: log exceptions with exception() calls
Log exceptions with loggers `exception()` methods.
1 parent 3f15d22 commit 8ec925a

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

mxcubecore/Command/Tango.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ def __init__(self, name, command, tangoname=None, username=None, **kwargs):
6666
def init_device(self):
6767
try:
6868
self.device = DeviceProxy(self.device_name)
69-
except tango.DevFailed as traceback:
70-
last_error = traceback[-1]
71-
logging.getLogger("HWR").error(
72-
"%s: %s", str(self.name()), last_error["desc"]
69+
except tango.DevFailed:
70+
logging.getLogger("HWR").exception(
71+
"Failed to set-up tango command %s on %s device",
72+
self.name(),
73+
self.device_name,
7374
)
7475
self.device = None
7576
else:
@@ -92,9 +93,11 @@ def __call__(self, *args, **kwargs):
9293
ret = tango_cmd_object(
9394
*args
9495
) # eval('self.device.%s(*%s)' % (self.command, args))
95-
except tango.DevFailed as error_dict:
96-
logging.getLogger("HWR").error(
97-
"%s: Tango, %s", str(self.name()), error_dict
96+
except tango.DevFailed:
97+
logging.getLogger("HWR").exception(
98+
"Failed to run tango command %s on %s device",
99+
self.name(),
100+
self.device_name,
98101
)
99102
except Exception:
100103
logging.getLogger("HWR").exception(
@@ -247,11 +250,12 @@ def continue_init(self, _):
247250
def init_device(self):
248251
try:
249252
self.device = DeviceProxy(self.device_name)
250-
except tango.DevFailed as traceback:
253+
except tango.DevFailed:
251254
self.imported = False
252-
last_error = traceback[-1]
253-
logging.getLogger("HWR").error(
254-
"%s: %s", str(self.name()), last_error["desc"]
255+
logging.getLogger("HWR").exception(
256+
"Failed to set-up tango channel %s on %s device",
257+
self.name(),
258+
self.device_name,
255259
)
256260
else:
257261
self.imported = True

ruff.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ convention = "google"
184184
"SLF001",
185185
"TD002",
186186
"TD003",
187-
"TRY400",
188187
]
189188
"mxcubecore/Command/Tine.py" = [
190189
"A002",

0 commit comments

Comments
 (0)