diff --git a/sendspin/utils.py b/sendspin/utils.py index d259ed8..c4dace3 100644 --- a/sendspin/utils.py +++ b/sendspin/utils.py @@ -3,6 +3,7 @@ from __future__ import annotations import asyncio +import logging import platform import sys import uuid @@ -13,6 +14,8 @@ from aiosendspin.models.core import DeviceInfo +logger = logging.getLogger(__name__) + _T = TypeVar("_T") # Check if eager_start is supported (Python 3.12+) @@ -61,11 +64,25 @@ def create_task( TASKS.add(task) task.add_done_callback(TASKS.discard) - task.add_done_callback(lambda t: t.exception() if not t.cancelled() else None) + task.add_done_callback(_log_task_exception) return task +def _log_task_exception(task: asyncio.Task[Any]) -> None: + """Log a fire-and-forget background task failure instead of swallowing it. + + Retrieving the exception suppresses "exception was never retrieved" + warnings, but the previous lambda then discarded it — every background + failure (hook/amixer/PulseAudio volume errors included) was invisible. + """ + if task.cancelled(): + return + exc = task.exception() + if exc is not None: + logger.error("Background task %r failed", task.get_name(), exc_info=exc) + + def _detect_mac_address() -> str | None: """Return a stable hardware MAC address, or None if only a synthesized one is available.