feat: implement slot_error_boundary decorator and add unit tests for session and device controllers

This commit is contained in:
jack
2026-06-18 21:01:37 -07:00
parent 5514653b94
commit 7206334a27
6 changed files with 353 additions and 1 deletions
+29
View File
@@ -0,0 +1,29 @@
import logging
from functools import wraps
def slot_error_boundary(func):
"""Wrap a @Slot method so exceptions are logged + signalled to QML.
Usage (stack under @Slot):
@Slot()
@slot_error_boundary
def myMethod(self) -> None:
...
On exception:
- Logs full traceback via logger.exception()
- Emits logMessage signal with human-readable error (if available)
- Returns None so QML never sees a crash
"""
@wraps(func)
def wrapper(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except Exception as e:
logger = logging.getLogger(self.__class__.__module__)
logger.exception("Slot '%s' raised: %s", func.__name__, e)
if hasattr(self, "logMessage"):
self.logMessage.emit(f"Error in {func.__name__}: {str(e)}")
return None
return wrapper