[commands] Don't raise ExtensionNotFound for ImportErrors in modules

Now loading an extension that _contains_ a failed import will fail
with ExtensionFailed, rather than ExtensionNotFound.
This commit is contained in:
Benjamin Mintz
2019-06-24 06:12:23 +00:00
committed by Rapptz
parent 3961e7ef6d
commit 0a21591d0c
2 changed files with 23 additions and 17 deletions

View File

@ -503,7 +503,7 @@ class NoEntryPointError(ExtensionError):
super().__init__("Extension {!r} has no 'setup' function.".format(name), name=name)
class ExtensionFailed(ExtensionError):
"""An exception raised when an extension failed to load during execution of the ``setup`` entry point.
"""An exception raised when an extension failed to load during execution of the module or ``setup`` entry point.
This inherits from :exc:`ExtensionError`
@ -521,19 +521,21 @@ class ExtensionFailed(ExtensionError):
super().__init__(fmt.format(name, original), name=name)
class ExtensionNotFound(ExtensionError):
"""An exception raised when an extension failed to be imported.
"""An exception raised when an extension is not found.
This inherits from :exc:`ExtensionError`
.. versionchanged:: 1.3.0
Made the ``original`` attribute always None.
Attributes
-----------
name: :class:`str`
The extension that had the error.
original: :exc:`ImportError`
The original exception that was raised. You can also get this via
the ``__cause__`` attribute.
original: :class:`NoneType`
Always ``None`` for backwards compatibility.
"""
def __init__(self, name, original):
self.original = original
def __init__(self, name, original=None):
self.original = None
fmt = 'Extension {0!r} could not be loaded.'
super().__init__(fmt.format(name), name=name)