From a1c0573e09ac0dc212255b4921db6fc6ad91acba Mon Sep 17 00:00:00 2001 From: Jacob Henry Date: Tue, 20 Nov 2018 16:28:49 -0500 Subject: [PATCH] Better error logging --- client_wrapper.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/client_wrapper.py b/client_wrapper.py index 6d14896..f40dd6d 100644 --- a/client_wrapper.py +++ b/client_wrapper.py @@ -1,5 +1,6 @@ import asyncio -from typing import List, Any, AsyncGenerator +import traceback +from typing import List, Any, AsyncGenerator, Coroutine, TypeVar from slackclient import SlackClient # Obvious @@ -14,6 +15,17 @@ api_file.close() # Enable to do single-threaded and have better exceptions DEBUG_MODE = False +A, B, C = TypeVar("A"), TypeVar("B"), TypeVar("C") + + +async def _loud_mouth(c: Coroutine[A, B, C]) -> Coroutine[A, B, C]: + # Print exceptions as they pass through + try: + return await c + except Exception: + traceback.print_exc() + raise + class ClientWrapper(object): """ @@ -81,7 +93,7 @@ class ClientWrapper(object): # If we get a coro back, then task it up and set consumption appropriately if coro is not None: print("Spawned task") - yield asyncio.create_task(coro) + yield asyncio.create_task(_loud_mouth(coro)) if hook.consumes: break