From 23542dc675b251418e1aa7ac2473a12831634038 Mon Sep 17 00:00:00 2001 From: Romain Dorgueil Date: Thu, 2 Nov 2017 00:17:03 +0100 Subject: [PATCH] Removing old error handler. --- bonobo/strategies/executor.py | 18 +++++++++------- bonobo/util/errors.py | 39 ----------------------------------- 2 files changed, 11 insertions(+), 46 deletions(-) delete mode 100644 bonobo/util/errors.py diff --git a/bonobo/strategies/executor.py b/bonobo/strategies/executor.py index 3bfabc6..24ca154 100644 --- a/bonobo/strategies/executor.py +++ b/bonobo/strategies/executor.py @@ -1,11 +1,15 @@ import time + +import sys + +import mondrian import traceback from concurrent.futures import Executor, ProcessPoolExecutor, ThreadPoolExecutor +from bonobo.util import get_name from bonobo.constants import BEGIN, END from bonobo.strategies.base import Strategy from bonobo.structs.bags import Bag -from bonobo.util.errors import print_error class ExecutorStrategy(Strategy): @@ -47,16 +51,16 @@ class ExecutorStrategy(Strategy): def _runner(): try: node.start() - except Exception as exc: - print_error(exc, traceback.format_exc(), context=node, method='start') + except Exception: + mondrian.excepthook(*sys.exc_info(), context='Could not start node {}.'.format(get_name(node))) node.input.on_end() else: node.loop() try: node.stop() - except Exception as exc: - print_error(exc, traceback.format_exc(), context=node, method='stop') + except Exception: + mondrian.excepthook(*sys.exc_info(), context='Could not stop node {}.'.format(get_name(node))) futures.append(executor.submit(_runner)) @@ -68,8 +72,8 @@ class ExecutorStrategy(Strategy): with plugin: try: plugin.loop() - except Exception as exc: - print_error(exc, traceback.format_exc(), context=plugin) + except Exception: + mondrian.excepthook(*sys.exc_info(), context='In plugin loop for {}...'.format(get_name(plugin))) futures.append(executor.submit(_runner)) diff --git a/bonobo/util/errors.py b/bonobo/util/errors.py deleted file mode 100644 index cae2789..0000000 --- a/bonobo/util/errors.py +++ /dev/null @@ -1,39 +0,0 @@ -import sys -from textwrap import indent - - -def _get_error_message(exc): - if hasattr(exc, '__str__'): - message = str(exc) - return message[0].upper() + message[1:] - return '\n'.join(exc.args), - - -def print_error(exc, trace, context=None, method=None): - """ - Error handler. Whatever happens in a plugin or component, if it looks like an exception, taste like an exception - or somehow make me think it is an exception, I'll handle it. - - :param exc: the culprit - :param trace: Hercule Poirot's logbook. - :return: to hell - """ - - from colorama import Fore, Style - - prefix = '{}{} | {}'.format(Fore.RED, Style.BRIGHT, Style.RESET_ALL) - - print( - Style.BRIGHT, - Fore.RED, - type(exc).__name__, - ' (in {}{})'.format(type(context).__name__, '.{}()'.format(method) if method else '') if context else '', - Style.RESET_ALL, - '\n', - indent(_get_error_message(exc), prefix + Style.BRIGHT), - Style.RESET_ALL, - sep='', - file=sys.stderr, - ) - print(prefix, file=sys.stderr) - print(indent(trace, prefix, predicate=lambda line: True), file=sys.stderr)