diff --git a/librarian/discord/bot.py b/librarian/discord/bot.py index edc1820..f4da059 100644 --- a/librarian/discord/bot.py +++ b/librarian/discord/bot.py @@ -36,14 +36,24 @@ def __init__( super().__init__(*args, command_prefix=self.COMMAND_PREFIX, **kwargs) - async def on_command_error(self, ctx, exception): + async def _on_command_error_inner(self, ctx, exception): if isinstance(exception, commands_errors.CommandNotFound): return await ctx.message.channel.send( content="no such command `{}` -- try `{}help` instead".format( ctx.invoked_with, self.COMMAND_PREFIX ) ) - return await super().on_command_error(ctx, exception) + else: + return await super().on_command_error(ctx, exception) + + async def on_command_error(self, ctx, exception): + try: + return await self._on_command_error_inner(ctx, exception) + except discord.errors.DiscordException as new_exc: + logger.info( + "Failed to notify %r in #%d about the error %r: %s", + ctx.message.author, ctx.message.channel.id, exception, new_exc + ) def setup(self): self.add_cog(pulls.Pulls()) diff --git a/librarian/discord/cogs/background/github.py b/librarian/discord/cogs/background/github.py index 5bea33d..e4e27aa 100644 --- a/librarian/discord/cogs/background/github.py +++ b/librarian/discord/cogs/background/github.py @@ -197,7 +197,10 @@ async def fetch_pulls(self, numbers: typing.Set[int]) -> typing.List[dict]: if isinstance(result, Exception): logger.error("%s: couldn't fetch pull #%s: %s", self.name, number, result) else: - ok.append(result) + if result is None: + logger.error("%s: received None for a pull #%d during fetching", self.name, result) + else: + ok.append(result) return ok @tasks.loop(seconds=INTERVAL)