Skip to content

Commit 150fb49

Browse files
author
Eviee Py
committed
Fix event_error handling from component listeners.
1 parent 71da029 commit 150fb49

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

twitchio/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from .models.teams import Team
4444
from .payloads import EventErrorPayload
4545
from .user import ActiveExtensions, Extension, PartialUser, User
46-
from .utils import EventWaiter
46+
from .utils import EventWaiter, unwrap_function
4747
from .web import AiohttpAdapter
4848
from .web.utils import BaseAdapter
4949

@@ -212,7 +212,9 @@ async def _dispatch(self, listener: Callable[..., Coroutine[Any, Any, None]], *,
212212
await called_
213213
except Exception as e:
214214
try:
215-
payload: EventErrorPayload = EventErrorPayload(error=e, listener=listener, original=original)
215+
payload: EventErrorPayload = EventErrorPayload(
216+
error=e, listener=unwrap_function(listener), original=original
217+
)
216218
await self.event_error(payload)
217219
except Exception as inner:
218220
logger.error(

twitchio/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import asyncio
2929
import colorsys
3030
import datetime
31+
import functools
3132
import json
3233
import logging
3334
import os
@@ -988,3 +989,15 @@ def is_inside_class(func: Callable[..., Any]) -> bool:
988989
return False
989990
(remaining, _, _) = func.__qualname__.rpartition(".")
990991
return not remaining.endswith("<locals>")
992+
993+
994+
def unwrap_function(function: Callable[..., Any], /) -> Callable[..., Any]:
995+
partial = functools.partial
996+
997+
while True:
998+
if hasattr(function, "__wrapped__"):
999+
function = function.__wrapped__ # type: ignore
1000+
elif isinstance(function, partial):
1001+
function = function.func
1002+
else:
1003+
return function

0 commit comments

Comments
 (0)