Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert: #1945 #2103

Merged
merged 2 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ These changes are available on the `master` branch, but have not yet been releas
([#2063](https://github.com/Pycord-Development/pycord/pull/2063))
- `default_avatar` behavior changes depending on the user's username migration status.
([#2087](https://github.com/Pycord-Development/pycord/pull/2087))
- `Client.on_error()` now has an `exception` parameter for easier error handling.
([#1945](https://github.com/Pycord-Development/pycord/pull/1945))
- Typehinted `command_prefix` and `help_command` arguments properly.
([#2099](https://github.com/Pycord-Development/pycord/pull/2099))

Expand Down
8 changes: 3 additions & 5 deletions discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ async def _run_event(
await coro(*args, **kwargs)
except asyncio.CancelledError:
pass
except Exception as exc:
except Exception:
try:
await self.on_error(event_name, exc, *args, **kwargs)
await self.on_error(event_name, *args, **kwargs)
except asyncio.CancelledError:
pass

Expand Down Expand Up @@ -481,9 +481,7 @@ def dispatch(self, event: str, *args: Any, **kwargs: Any) -> None:
for coro in once_listeners:
self._event_handlers[method].remove(coro)

async def on_error(
self, event_method: str, exception: Exception, *args: Any, **kwargs: Any
) -> None:
async def on_error(self, event_method: str, *args: Any, **kwargs: Any) -> None:
"""|coro|

The default error handler provided by the client.
Expand Down
8 changes: 4 additions & 4 deletions docs/api/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,17 @@ Channels

Connection
----------
.. function:: on_error(event, exception, *args, **kwargs)
.. function:: on_error(event, *args, **kwargs)

Usually when an event raises an uncaught exception, a traceback is
printed to stderr and the exception is ignored. If you want to
change this behaviour and handle the exception for whatever reason
yourself, this event can be overridden. Which, when done, will
suppress the default action of printing the traceback.

The information of the exception raised and the exception itself can
be retrieved with a standard call to :func:`sys.exc_info`.

If you want exception to propagate out of the :class:`Client` class
you can define an ``on_error`` handler consisting of a single empty
:ref:`raise statement <py:raise>`. Exceptions raised by ``on_error`` will not be
Expand All @@ -276,9 +279,6 @@ Connection
:param event: The name of the event that raised the exception.
:type event: :class:`str`

:param exception: The exception raised by the event.
:type event: :class:`Exception`

:param args: The positional arguments for the event that raised the
exception.
:param kwargs: The keyword arguments for the event that raised the
Expand Down