From 18cc029918bd0775ad27f928bb54cd2d2cc33352 Mon Sep 17 00:00:00 2001 From: Snipy7374 <100313469+Snipy7374@users.noreply.github.com> Date: Sun, 20 Aug 2023 17:43:34 +0200 Subject: [PATCH] feat(commands.cog): pass errors raised by cog_unload to the bot's on_error (#1067) --- changelog/1046.feature.rst | 1 + disnake/ext/commands/cog.py | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 changelog/1046.feature.rst diff --git a/changelog/1046.feature.rst b/changelog/1046.feature.rst new file mode 100644 index 0000000000..4335e7e17d --- /dev/null +++ b/changelog/1046.feature.rst @@ -0,0 +1 @@ +|commands| Log errors raised by :meth:`.ext.commands.Cog.cog_unload`. diff --git a/disnake/ext/commands/cog.py b/disnake/ext/commands/cog.py index a0ec377d53..a0305ccea7 100644 --- a/disnake/ext/commands/cog.py +++ b/disnake/ext/commands/cog.py @@ -4,6 +4,7 @@ import asyncio import inspect +import logging from typing import ( TYPE_CHECKING, Any, @@ -48,6 +49,7 @@ FuncT = TypeVar("FuncT", bound=Callable[..., Any]) MISSING: Any = disnake.utils.MISSING +_log = logging.getLogger(__name__) def _cog_special_method(func: FuncT) -> FuncT: @@ -895,6 +897,7 @@ def _eject(self, bot: AnyBot) -> None: pass try: self.cog_unload() - except Exception: - # TODO: Consider calling the bot's on_error handler here - pass + except Exception as e: + _log.error( + "An error occurred while unloading the %s cog.", self.qualified_name, exc_info=e + )