Skip to content

Commit fa22698

Browse files
committed
Log exceptions from commands
1 parent d3a4858 commit fa22698

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/fastcs/methods/command.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
from types import MethodType
33

44
from fastcs.controllers import BaseController
5+
from fastcs.logging import bind_logger
56
from fastcs.methods.method import Controller_T, Method
67

8+
logger = bind_logger(logger_name=__name__)
9+
710
UnboundCommandCallback = Callable[[Controller_T], Coroutine[None, None, None]]
811
"""A Command callback that is unbound and must be called with a `Controller` instance"""
912
CommandCallback = Callable[[], Coroutine[None, None, None]]
@@ -28,7 +31,18 @@ def _validate(self, fn: CommandCallback) -> None:
2831
raise TypeError(f"Command method cannot have arguments: {fn}")
2932

3033
async def __call__(self):
31-
return await self._fn()
34+
return await self.fn()
35+
36+
@property
37+
def fn(self):
38+
async def command():
39+
try:
40+
return await self._fn()
41+
except Exception:
42+
logger.exception("Command failed", fn=self._fn)
43+
raise
44+
45+
return command
3246

3347

3448
class UnboundCommand(Method[Controller_T]):

0 commit comments

Comments
 (0)