[commands] Exceptions raised while invocation raise CommandInvokeError.
This change should make it a bit more intuitive to get the original exception without having the gotcha of checking ``isinstance`` inside the error handler.
This commit is contained in:
parent
d914c0a4e4
commit
43bbecd519
@ -47,7 +47,7 @@ def inject_context(ctx, coro):
|
|||||||
try:
|
try:
|
||||||
ret = yield from coro(*args, **kwargs)
|
ret = yield from coro(*args, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise CommandError("Exception raised while executing command") from e
|
raise CommandInvokeError(e) from e
|
||||||
return ret
|
return ret
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ from discord.errors import DiscordException
|
|||||||
|
|
||||||
__all__ = [ 'CommandError', 'MissingRequiredArgument', 'BadArgument',
|
__all__ = [ 'CommandError', 'MissingRequiredArgument', 'BadArgument',
|
||||||
'NoPrivateMessage', 'CheckFailure', 'CommandNotFound',
|
'NoPrivateMessage', 'CheckFailure', 'CommandNotFound',
|
||||||
'DisabledCommand' ]
|
'DisabledCommand', 'CommandInvokeError' ]
|
||||||
|
|
||||||
class CommandError(DiscordException):
|
class CommandError(DiscordException):
|
||||||
"""The base exception type for all command related errors.
|
"""The base exception type for all command related errors.
|
||||||
@ -74,3 +74,16 @@ class CheckFailure(CommandError):
|
|||||||
class DisabledCommand(CommandError):
|
class DisabledCommand(CommandError):
|
||||||
"""Exception raised when the command being invoked is disabled."""
|
"""Exception raised when the command being invoked is disabled."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class CommandInvokeError(CommandError):
|
||||||
|
"""Exception raised when the command being invoked raised an exception.
|
||||||
|
|
||||||
|
Attributes
|
||||||
|
-----------
|
||||||
|
original
|
||||||
|
The original exception that was raised. You can also get this via
|
||||||
|
the ``__cause__`` attribute.
|
||||||
|
"""
|
||||||
|
def __init__(self, e):
|
||||||
|
self.original = e
|
||||||
|
super().__init__('Command raised an exception: {0.__class__.__name__}: {0}'.format(e))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user