aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2019-12-27 14:37:58 -0800
committerGravatar MarkKoz <[email protected]>2020-02-12 10:07:46 -0800
commit6c1164fe1bf95d49373722051a00f11e0f17a699 (patch)
tree8238521f52b478e3dbdb8cccb6ec44e8668c2b56
parentSync: mention core devs when results are shown & fix missing space (diff)
Sync: handle API errors gracefully
The whole sync is aborted when an error is caught for simplicity's sake. The sync message is edited to display the error and the traceback is logged. To distinguish an error from an abort/timeout, the latter now uses a warning emoji while the former uses the red cross.
-rw-r--r--bot/cogs/sync/syncers.py31
1 files changed, 21 insertions, 10 deletions
diff --git a/bot/cogs/sync/syncers.py b/bot/cogs/sync/syncers.py
index bebea8f19..4286609da 100644
--- a/bot/cogs/sync/syncers.py
+++ b/bot/cogs/sync/syncers.py
@@ -7,6 +7,7 @@ from discord import Guild, HTTPException, Member, Message
from discord.ext.commands import Context
from bot import constants
+from bot.api import ResponseCodeError
from bot.bot import Bot
log = logging.getLogger(__name__)
@@ -119,7 +120,9 @@ class Syncer(abc.ABC):
return True
else:
log.warning(f"The {self.name} syncer was aborted or timed out!")
- await message.edit(content=f':x: {mention}{self.name} sync aborted or timed out!')
+ await message.edit(
+ content=f':warning: {mention}{self.name} sync aborted or timed out!'
+ )
return False
@abc.abstractmethod
@@ -161,17 +164,25 @@ class Syncer(abc.ABC):
if not confirmed:
return # Sync aborted.
- await self._sync(diff)
+ # Preserve the core-dev role mention in the message edits so users aren't confused about
+ # where notifications came from.
+ mention = self._CORE_DEV_MENTION if author.bot else ""
+
+ try:
+ await self._sync(diff)
+ except ResponseCodeError as e:
+ log.exception(f"{self.name} syncer failed!")
+
+ # Don't show response text because it's probably some really long HTML.
+ results = f"status {e.status}\n```{e.response_json or 'See log output for details'}```"
+ content = f":x: {mention}Synchronisation of {self.name}s failed: {results}"
+ else:
+ results = ", ".join(f"{name} `{total}`" for name, total in totals.items())
+ log.info(f"{self.name} syncer finished: {results}.")
+ content = f":ok_hand: {mention}Synchronisation of {self.name}s complete: {results}"
- results = ", ".join(f"{name} `{total}`" for name, total in totals.items())
- log.info(f"{self.name} syncer finished: {results}.")
if message:
- # Preserve the core-dev role mention in the message edits so users aren't confused about
- # where notifications came from.
- mention = self._CORE_DEV_MENTION if author.bot else ""
- await message.edit(
- content=f":ok_hand: {mention}Synchronisation of {self.name}s complete: {results}"
- )
+ await message.edit(content=content)
class RoleSyncer(Syncer):