Skip to content

Commit 01d7850

Browse files
authored
Merge branch 'Pycord-Development:master' into master
2 parents 361858a + f261b84 commit 01d7850

File tree

2 files changed

+82
-82
lines changed

2 files changed

+82
-82
lines changed

discord/errors.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
'ConnectionClosed',
5353
'PrivilegedIntentsRequired',
5454
'InteractionResponded',
55+
'ExtensionError',
56+
'ExtensionAlreadyLoaded',
57+
'ExtensionNotLoaded',
58+
'NoEntryPointError',
59+
'ExtensionFailed',
60+
'ExtensionNotFound'
5561
)
5662

5763

@@ -275,3 +281,79 @@ class InteractionResponded(ClientException):
275281
def __init__(self, interaction: Interaction):
276282
self.interaction: Interaction = interaction
277283
super().__init__('This interaction has already been responded to before')
284+
285+
class ExtensionError(DiscordException):
286+
"""Base exception for extension related errors.
287+
288+
This inherits from :exc:`~discord.DiscordException`.
289+
290+
Attributes
291+
------------
292+
name: :class:`str`
293+
The extension that had an error.
294+
"""
295+
def __init__(self, message: Optional[str] = None, *args: Any, name: str) -> None:
296+
self.name: str = name
297+
message = message or f'Extension {name!r} had an error.'
298+
# clean-up @everyone and @here mentions
299+
m = message.replace('@everyone', '@\u200beveryone').replace('@here', '@\u200bhere')
300+
super().__init__(m, *args)
301+
302+
class ExtensionAlreadyLoaded(ExtensionError):
303+
"""An exception raised when an extension has already been loaded.
304+
305+
This inherits from :exc:`ExtensionError`
306+
"""
307+
def __init__(self, name: str) -> None:
308+
super().__init__(f'Extension {name!r} is already loaded.', name=name)
309+
310+
class ExtensionNotLoaded(ExtensionError):
311+
"""An exception raised when an extension was not loaded.
312+
313+
This inherits from :exc:`ExtensionError`
314+
"""
315+
def __init__(self, name: str) -> None:
316+
super().__init__(f'Extension {name!r} has not been loaded.', name=name)
317+
318+
class NoEntryPointError(ExtensionError):
319+
"""An exception raised when an extension does not have a ``setup`` entry point function.
320+
321+
This inherits from :exc:`ExtensionError`
322+
"""
323+
def __init__(self, name: str) -> None:
324+
super().__init__(f"Extension {name!r} has no 'setup' function.", name=name)
325+
326+
class ExtensionFailed(ExtensionError):
327+
"""An exception raised when an extension failed to load during execution of the module or ``setup`` entry point.
328+
329+
This inherits from :exc:`ExtensionError`
330+
331+
Attributes
332+
-----------
333+
name: :class:`str`
334+
The extension that had the error.
335+
original: :exc:`Exception`
336+
The original exception that was raised. You can also get this via
337+
the ``__cause__`` attribute.
338+
"""
339+
def __init__(self, name: str, original: Exception) -> None:
340+
self.original: Exception = original
341+
msg = f'Extension {name!r} raised an error: {original.__class__.__name__}: {original}'
342+
super().__init__(msg, name=name)
343+
344+
class ExtensionNotFound(ExtensionError):
345+
"""An exception raised when an extension is not found.
346+
347+
This inherits from :exc:`ExtensionError`
348+
349+
.. versionchanged:: 1.3
350+
Made the ``original`` attribute always None.
351+
352+
Attributes
353+
-----------
354+
name: :class:`str`
355+
The extension that had the error.
356+
"""
357+
def __init__(self, name: str) -> None:
358+
msg = f'Extension {name!r} could not be loaded.'
359+
super().__init__(msg, name=name)

discord/ext/commands/errors.py

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,6 @@
8686
'UnexpectedQuoteError',
8787
'InvalidEndOfQuotedStringError',
8888
'ExpectedClosingQuoteError',
89-
'ExtensionError',
90-
'ExtensionAlreadyLoaded',
91-
'ExtensionNotLoaded',
92-
'NoEntryPointError',
93-
'ExtensionFailed',
94-
'ExtensionNotFound',
9589
'CommandRegistrationError',
9690
'FlagError',
9791
'BadFlagArgument',
@@ -818,82 +812,6 @@ def __init__(self, close_quote: str) -> None:
818812
self.close_quote: str = close_quote
819813
super().__init__(f'Expected closing {close_quote}.')
820814

821-
class ExtensionError(DiscordException):
822-
"""Base exception for extension related errors.
823-
824-
This inherits from :exc:`~discord.DiscordException`.
825-
826-
Attributes
827-
------------
828-
name: :class:`str`
829-
The extension that had an error.
830-
"""
831-
def __init__(self, message: Optional[str] = None, *args: Any, name: str) -> None:
832-
self.name: str = name
833-
message = message or f'Extension {name!r} had an error.'
834-
# clean-up @everyone and @here mentions
835-
m = message.replace('@everyone', '@\u200beveryone').replace('@here', '@\u200bhere')
836-
super().__init__(m, *args)
837-
838-
class ExtensionAlreadyLoaded(ExtensionError):
839-
"""An exception raised when an extension has already been loaded.
840-
841-
This inherits from :exc:`ExtensionError`
842-
"""
843-
def __init__(self, name: str) -> None:
844-
super().__init__(f'Extension {name!r} is already loaded.', name=name)
845-
846-
class ExtensionNotLoaded(ExtensionError):
847-
"""An exception raised when an extension was not loaded.
848-
849-
This inherits from :exc:`ExtensionError`
850-
"""
851-
def __init__(self, name: str) -> None:
852-
super().__init__(f'Extension {name!r} has not been loaded.', name=name)
853-
854-
class NoEntryPointError(ExtensionError):
855-
"""An exception raised when an extension does not have a ``setup`` entry point function.
856-
857-
This inherits from :exc:`ExtensionError`
858-
"""
859-
def __init__(self, name: str) -> None:
860-
super().__init__(f"Extension {name!r} has no 'setup' function.", name=name)
861-
862-
class ExtensionFailed(ExtensionError):
863-
"""An exception raised when an extension failed to load during execution of the module or ``setup`` entry point.
864-
865-
This inherits from :exc:`ExtensionError`
866-
867-
Attributes
868-
-----------
869-
name: :class:`str`
870-
The extension that had the error.
871-
original: :exc:`Exception`
872-
The original exception that was raised. You can also get this via
873-
the ``__cause__`` attribute.
874-
"""
875-
def __init__(self, name: str, original: Exception) -> None:
876-
self.original: Exception = original
877-
msg = f'Extension {name!r} raised an error: {original.__class__.__name__}: {original}'
878-
super().__init__(msg, name=name)
879-
880-
class ExtensionNotFound(ExtensionError):
881-
"""An exception raised when an extension is not found.
882-
883-
This inherits from :exc:`ExtensionError`
884-
885-
.. versionchanged:: 1.3
886-
Made the ``original`` attribute always None.
887-
888-
Attributes
889-
-----------
890-
name: :class:`str`
891-
The extension that had the error.
892-
"""
893-
def __init__(self, name: str) -> None:
894-
msg = f'Extension {name!r} could not be loaded.'
895-
super().__init__(msg, name=name)
896-
897815
class CommandRegistrationError(ClientException):
898816
"""An exception raised when the command can't be added
899817
because the name is already taken by a different command.

0 commit comments

Comments
 (0)