Skip to content

Commit 8a4d22e

Browse files
committed
Catch errors in AS e2ee things instead of failing transaction
1 parent 7c6fb06 commit 8a4d22e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

mautrix/appservice/as_handler.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,20 @@ async def handle_transaction(
267267
except SerializerError:
268268
self.log.exception("Failed to deserialize to-device event %s", raw_td)
269269
else:
270-
await self.to_device_handler(td)
270+
try:
271+
await self.to_device_handler(td)
272+
except:
273+
self.log.exception("Exception in Matrix to-device event handler")
271274
if device_lists and self.device_list_handler:
272-
await self.device_list_handler(device_lists)
275+
try:
276+
await self.device_list_handler(device_lists)
277+
except Exception:
278+
self.log.exception("Exception in Matrix device list change handler")
273279
if otk_counts and self.otk_handler:
274-
await self.otk_handler(otk_counts)
280+
try:
281+
await self.otk_handler(otk_counts)
282+
except Exception:
283+
self.log.exception("Exception in Matrix OTK count handler")
275284
for raw_edu in ephemeral or []:
276285
try:
277286
edu = EphemeralEvent.deserialize(raw_edu)
@@ -304,6 +313,7 @@ async def try_handle(handler_func: HandlerFunc):
304313
self.log.exception("Exception in Matrix event handler")
305314

306315
for handler in self.event_handlers:
316+
# TODO add option to handle events synchronously
307317
asyncio.create_task(try_handle(handler))
308318

309319
def matrix_event_handler(self, func: HandlerFunc) -> HandlerFunc:

0 commit comments

Comments
 (0)