Skip to content

Commit

Permalink
feat(commands.cog): pass errors raised by cog_unload to the bot's on_…
Browse files Browse the repository at this point in the history
…error (#1067)
  • Loading branch information
Snipy7374 authored Aug 20, 2023
1 parent a491421 commit 18cc029
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/1046.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
|commands| Log errors raised by :meth:`.ext.commands.Cog.cog_unload`.
9 changes: 6 additions & 3 deletions disnake/ext/commands/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import asyncio
import inspect
import logging
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
)

0 comments on commit 18cc029

Please sign in to comment.