diff --git a/aprsd/packets/collector.py b/aprsd/packets/collector.py index d6c6659..2c9d334 100644 --- a/aprsd/packets/collector.py +++ b/aprsd/packets/collector.py @@ -1,9 +1,13 @@ +import logging from typing import Callable, Protocol, runtime_checkable from aprsd.packets import core from aprsd.utils import singleton +LOG = logging.getLogger("APRSD") + + @runtime_checkable class PacketMonitor(Protocol): """Protocol for Monitoring packets in some way.""" @@ -29,7 +33,11 @@ class PacketCollector: for name in self.monitors: cls = name() if isinstance(cls, PacketMonitor): - cls.rx(packet) + try: + cls.rx(packet) + except Exception as e: + LOG.error(f"Error in monitor {name} (rx): {e}") + else: raise TypeError(f"Monitor {name} is not a PacketMonitor") @@ -37,6 +45,9 @@ class PacketCollector: for name in self.monitors: cls = name() if isinstance(cls, PacketMonitor): - cls.tx(packet) + try: + cls.tx(packet) + except Exception as e: + LOG.error(f"Error in monitor {name} (tx): {e}") else: raise TypeError(f"Monitor {name} is not a PacketMonitor") diff --git a/aprsd/stats/collector.py b/aprsd/stats/collector.py index 3325669..91e1833 100644 --- a/aprsd/stats/collector.py +++ b/aprsd/stats/collector.py @@ -1,8 +1,12 @@ +import logging from typing import Callable, Protocol, runtime_checkable from aprsd.utils import singleton +LOG = logging.getLogger("APRSD") + + @runtime_checkable class StatsProducer(Protocol): """The StatsProducer protocol is used to define the interface for collecting stats.""" @@ -22,7 +26,10 @@ class Collector: for name in self.producers: cls = name() if isinstance(cls, StatsProducer): - stats[cls.__class__.__name__] = cls.stats(serializable=serializable) + try: + stats[cls.__class__.__name__] = cls.stats(serializable=serializable) + except Exception as e: + LOG.error(f"Error in producer {name} (stats): {e}") else: raise TypeError(f"{cls} is not an instance of StatsProducer") return stats