diff --git a/python/src/uagents/agent.py b/python/src/uagents/agent.py index d6c1a2e3..c155abb9 100644 --- a/python/src/uagents/agent.py +++ b/python/src/uagents/agent.py @@ -393,6 +393,8 @@ async def _startup(self): self._logger.exception(f"OS Error in startup handler: {ex}") except RuntimeError as ex: self._logger.exception(f"Runtime Error in startup handler: {ex}") + except Exception as ex: + self._logger.exception(f"Exception in startup handler: {ex}") async def _shutdown(self): for handler in self._on_shutdown: @@ -402,6 +404,8 @@ async def _shutdown(self): self._logger.exception(f"OS Error in shutdown handler: {ex}") except RuntimeError as ex: self._logger.exception(f"Runtime Error in shutdown handler: {ex}") + except Exception as ex: + self._logger.exception(f"Exception in shutdown handler: {ex}") def setup(self): # register the internal agent protocol @@ -496,6 +500,8 @@ async def _process_message_queue(self): self._logger.exception(f"OS Error in message handler: {ex}") except RuntimeError as ex: self._logger.exception(f"Runtime Error in message handler: {ex}") + except Exception as ex: + self._logger.exception(f"Exception in message handler: {ex}") class Bureau: diff --git a/python/src/uagents/context.py b/python/src/uagents/context.py index d42b8ec2..8ccd92db 100644 --- a/python/src/uagents/context.py +++ b/python/src/uagents/context.py @@ -250,12 +250,11 @@ async def send_raw( data=env.json(), ) as resp: success = resp.status == 200 + if not success: + self._logger.exception( + f"Unable to send envelope to {destination_address} @ {endpoint}" + ) except aiohttp.ClientConnectorError as ex: self._logger.exception(f"Failed to connect to {endpoint}: {ex}") except Exception as ex: self._logger.exception(f"Failed to send message to {destination}: {ex}") - - if not success: - self._logger.exception( - f"Unable to send envelope to {destination_address} @ {endpoint}" - )