From dfc53ef4bb4ff1726c7d2578e8353fde0f3263dd Mon Sep 17 00:00:00 2001 From: Shiz Date: Wed, 11 Jun 2014 06:32:45 +0200 Subject: [PATCH] Properly show exceptions in coroutines. --- pydle/async.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/pydle/async.py b/pydle/async.py index 1d55304..0d0ec6e 100644 --- a/pydle/async.py +++ b/pydle/async.py @@ -37,20 +37,14 @@ def coroutine(func): result.add_done_callback(handle_future) except StopIteration as e: return_future.set_result(getattr(e, 'value', None)) - except Exception as e: - return_future.set_exception(e) - try: - # Handle initial value. - gen = func(*args, **kwargs) - except Exception as e: - return_future.set_exception(e) + # Handle initial value. + gen = func(*args, **kwargs) + + # If this isn't a generator, then wrap the result with a future. + if not isinstance(gen, types.GeneratorType): + return_future.set_result(gen) return return_future - else: - # If this isn't a generator, then wrap the result with a future. - if not isinstance(gen, types.GeneratorType): - return_future.set_result(gen) - return return_future try: result = next(gen) @@ -59,8 +53,6 @@ def coroutine(func): result.add_done_callback(handle_future) except StopIteration as e: return_future.set_result(getattr(e, 'value', None)) - except Exception as e: - return_future.set_exception(e) return return_future return wrapper