From 1cd94a899ab6aa8b020c5de76f4034f1c6652ad5 Mon Sep 17 00:00:00 2001 From: alemidev Date: Fri, 12 Nov 2021 12:56:44 +0100 Subject: [PATCH] except registered callbacks individually --- aiocraft/client.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/aiocraft/client.py b/aiocraft/client.py index 1cffd5d..058c7e5 100644 --- a/aiocraft/client.py +++ b/aiocraft/client.py @@ -209,13 +209,19 @@ class Client: elif self.dispatcher.state == ConnectionState.PLAY: await self.play_logic(packet) - if self.dispatcher.state in self._packet_callbacks: - if Packet in self._packet_callbacks[self.dispatcher.state]: # callback for any packet - for cb in self._packet_callbacks[self.dispatcher.state][Packet]: - await cb(packet) - if packet.__class__ in self._packet_callbacks[self.dispatcher.state]: # callback for this packet - for cb in self._packet_callbacks[self.dispatcher.state][packet.__class__]: - await cb(packet) + if self.dispatcher.state in self._packet_callbacks: + if Packet in self._packet_callbacks[self.dispatcher.state]: # callback for any packet + for cb in self._packet_callbacks[self.dispatcher.state][Packet]: + try: + await cb(packet) + except Exception as e: + self._logger.exception("Exception while handling callback") + if packet.__class__ in self._packet_callbacks[self.dispatcher.state]: # callback for this packet + for cb in self._packet_callbacks[self.dispatcher.state][packet.__class__]: + try: + await cb(packet) + except Exception as e: + self._logger.exception("Exception while handling callback") self.dispatcher.incoming.task_done() except asyncio.TimeoutError: