Skip to content

Commit 07e5018

Browse files
committed
Make base exception and add docstrings
1 parent 911470e commit 07e5018

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

twitchio/ext/commands/bot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ async def load_module(self, name: str, *, package: str | None = None) -> None:
542542
spec.loader.exec_module(module) # type: ignore
543543
except Exception as e:
544544
del sys.modules[name]
545-
raise ModuleLoadFailure(e) from e
545+
raise ModuleLoadFailure(name, e) from e
546546

547547
try:
548548
entry = getattr(module, "setup")
@@ -559,7 +559,7 @@ async def load_module(self, name: str, *, package: str | None = None) -> None:
559559
except Exception as e:
560560
del sys.modules[name]
561561
await self._remove_module_remnants(module.__name__)
562-
raise ModuleLoadFailure(e) from e
562+
raise ModuleLoadFailure(name, e) from e
563563

564564
self.__modules[name] = module
565565

twitchio/ext/commands/exceptions.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,33 @@ def __init__(self, param: inspect.Parameter) -> None:
126126
super().__init__(f'"{param.name}" is a required argument which is missing.')
127127

128128

129-
class ModuleLoadFailure(TwitchioException):
130-
def __init__(self, exc: Exception) -> None:
131-
super().__init__(exc)
129+
class ModuleError(TwitchioException):
130+
"""Base exception for module related errors."""
132131

133132

134-
class NoEntryPointError(TwitchioException):
133+
class ModuleLoadFailure(ModuleError):
134+
"""An exception raised when a module failed to load during execution or `setup` entry point."""
135+
136+
def __init__(self, name: str, exc: Exception) -> None:
137+
super().__init__(name, exc)
138+
139+
140+
class NoEntryPointError(ModuleError):
141+
"""Exception raised when the module does not have a `setup` entry point coroutine."""
142+
135143
def __init__(self, msg: str) -> None:
136144
super().__init__(msg)
137145

138146

139-
class ModuleAlreadyLoadedError(TwitchioException):
147+
class ModuleAlreadyLoadedError(ModuleError):
148+
"""Exception raised when a module has already been loaded."""
149+
140150
def __init__(self, msg: str) -> None:
141151
super().__init__(msg)
142152

143153

144-
class ModuleNotLoadedError(TwitchioException):
154+
class ModuleNotLoadedError(ModuleError):
155+
"""An exception raised when a module was not loaded."""
156+
145157
def __init__(self, msg: str) -> None:
146158
super().__init__(msg)

0 commit comments

Comments
 (0)