Skip to content

Commit 5de68a6

Browse files
committed
Added EventException
1 parent ce1e10c commit 5de68a6

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

redis/event.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ async def dispatch_async(self, event: object):
4343
pass
4444

4545

46+
class EventException(Exception):
47+
"""
48+
Exception wrapper that adds an event object into exception context.
49+
"""
50+
def __init__(self, exception: Exception, event: object):
51+
self.exception = exception
52+
self.event = event
53+
super().__init__(exception)
54+
55+
4656
class EventDispatcher(EventDispatcherInterface):
4757
# TODO: Make dispatcher to accept external mappings.
4858
def __init__(self):
@@ -262,10 +272,10 @@ async def _re_auth_async(self, token):
262272
await pool.re_auth_callback(token)
263273

264274
def _raise_on_error(self, error: Exception):
265-
raise error
275+
raise EventException(error, self._event)
266276

267277
async def _raise_on_error_async(self, error: Exception):
268-
raise error
278+
raise EventException(error, self._event)
269279

270280

271281
class RegisterReAuthForSingleConnection(EventListenerInterface):
@@ -307,10 +317,10 @@ async def _re_auth_async(self, token):
307317
await self._event.connection.read_response()
308318

309319
def _raise_on_error(self, error: Exception):
310-
raise error
320+
raise EventException(error, self._event)
311321

312322
async def _raise_on_error_async(self, error: Exception):
313-
raise error
323+
raise EventException(error, self._event)
314324

315325

316326
class RegisterReAuthForAsyncClusterNodes(EventListenerInterface):
@@ -328,7 +338,7 @@ async def _re_auth(self, token: TokenInterface):
328338
await self._event.nodes[key].re_auth_callback(token)
329339

330340
async def _raise_on_error(self, error: Exception):
331-
raise error
341+
raise EventException(error, self._event)
332342

333343

334344
class RegisterReAuthForPubSub(EventListenerInterface):
@@ -337,11 +347,13 @@ def __init__(self):
337347
self._connection_pool = None
338348
self._client_type = None
339349
self._connection_lock = None
350+
self._event = None
340351

341352
def listen(self, event: AfterPubSubConnectionInstantiationEvent):
342353
if isinstance(
343354
event.pubsub_connection.credential_provider, StreamingCredentialProvider
344355
) and event.pubsub_connection.get_protocol() in [3, "3"]:
356+
self._event = event
345357
self._connection = event.pubsub_connection
346358
self._connection_pool = event.connection_pool
347359
self._client_type = event.client_type
@@ -375,7 +387,7 @@ async def _re_auth_async(self, token: TokenInterface):
375387
await self._connection_pool.re_auth_callback(token)
376388

377389
def _raise_on_error(self, error: Exception):
378-
raise error
390+
raise EventException(error, self._event)
379391

380392
async def _raise_on_error_async(self, error: Exception):
381-
raise error
393+
raise EventException(error, self._event)

0 commit comments

Comments
 (0)