From 07e10f0eb527cfbe08b2f65cc4fed6153314602b Mon Sep 17 00:00:00 2001 From: nex Date: Mon, 23 Jan 2023 16:35:29 +0000 Subject: [PATCH] Add error handling to uptime checker --- cogs/uptime.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cogs/uptime.py b/cogs/uptime.py index 4320fad..acf1403 100644 --- a/cogs/uptime.py +++ b/cogs/uptime.py @@ -64,6 +64,7 @@ class UptimeCompetition(commands.Cog): self.bot = bot self.http = AsyncClient() self._warning_posted = False + self.test_uptimes.add_exception_type(Exception) self.test_uptimes.start() self.last_result: list[UptimeEntry] = [] self.task_lock = asyncio.Lock() @@ -158,7 +159,11 @@ class UptimeCompetition(commands.Cog): if max_retries := target.get("max_retries"): request_kwargs["max_retries"] = max_retries kwargs: Dict[str, str | int | None] = {"target_id": target["id"], "target": target["uri"], "notes": ""} - attempts, response = await self._test_url(target["uri"], **request_kwargs) + try: + attempts, response = await self._test_url(target["uri"], **request_kwargs) + except Exception as e: + response = e + attempts = 1 if isinstance(response, Exception): kwargs["is_up"] = False kwargs["response_time"] = None @@ -240,7 +245,11 @@ class UptimeCompetition(commands.Cog): async def test_uptimes(self): self.task_event.clear() async with self.task_lock: - self.last_result = await self.do_test_uptimes() + try: + self.last_result = await self.do_test_uptimes() + except (Exception, ConnectionError): + print() + console.print_exception() self.task_event.set() uptime = discord.SlashCommandGroup("uptime", "Commands for the uptime competition.")