Skip to content

Commit

Permalink
chore: move success check and catch all exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jrriehl committed Aug 31, 2023
1 parent 4ac5c1a commit d011ca3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 6 additions & 0 deletions python/src/uagents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 4 additions & 5 deletions python/src/uagents/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)

0 comments on commit d011ca3

Please sign in to comment.