mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 12:18:59 +00:00
Wrap non-AppCommandError exceptions with TransformerError
This commit is contained in:
parent
b0501e56a0
commit
1f3aa377c3
@ -92,10 +92,11 @@ class TransformerError(AppCommandError):
|
|||||||
|
|
||||||
This inherits from :exc:`~discord.app_commands.AppCommandError`.
|
This inherits from :exc:`~discord.app_commands.AppCommandError`.
|
||||||
|
|
||||||
.. note::
|
If an exception occurs while converting that does not subclass
|
||||||
|
:exc:`AppCommandError` then the exception is wrapped into this exception.
|
||||||
If the transformer raises a custom :exc:`AppCommandError` then it will
|
The original exception can be retrieved using the ``__cause__`` attribute.
|
||||||
be propagated rather than wrapped into this exception.
|
Otherwise if the exception derives from :exc:`AppCommandError` then it will
|
||||||
|
be propagated as-is.
|
||||||
|
|
||||||
.. versionadded:: 2.0
|
.. versionadded:: 2.0
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ from typing import (
|
|||||||
Union,
|
Union,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .errors import TransformerError
|
from .errors import AppCommandError, TransformerError
|
||||||
from .models import AppCommandChannel, AppCommandThread, Choice
|
from .models import AppCommandChannel, AppCommandThread, Choice
|
||||||
from ..channel import StageChannel, StoreChannel, VoiceChannel, TextChannel, CategoryChannel
|
from ..channel import StageChannel, StoreChannel, VoiceChannel, TextChannel, CategoryChannel
|
||||||
from ..enums import AppCommandOptionType, ChannelType
|
from ..enums import AppCommandOptionType, ChannelType
|
||||||
@ -136,7 +136,13 @@ class CommandParameter:
|
|||||||
raise TransformerError(value, self.type, self._annotation)
|
raise TransformerError(value, self.type, self._annotation)
|
||||||
return choice
|
return choice
|
||||||
|
|
||||||
|
try:
|
||||||
return await self._annotation.transform(interaction, value)
|
return await self._annotation.transform(interaction, value)
|
||||||
|
except AppCommandError:
|
||||||
|
raise
|
||||||
|
except Exception as e:
|
||||||
|
raise TransformerError(value, self.type, self._annotation) from e
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user