Removing old error handler.

This commit is contained in:
Romain Dorgueil
2017-11-02 00:17:03 +01:00
parent fb86bc9507
commit 23542dc675
2 changed files with 11 additions and 46 deletions

View File

@ -1,11 +1,15 @@
import time import time
import sys
import mondrian
import traceback import traceback
from concurrent.futures import Executor, ProcessPoolExecutor, ThreadPoolExecutor from concurrent.futures import Executor, ProcessPoolExecutor, ThreadPoolExecutor
from bonobo.util import get_name
from bonobo.constants import BEGIN, END from bonobo.constants import BEGIN, END
from bonobo.strategies.base import Strategy from bonobo.strategies.base import Strategy
from bonobo.structs.bags import Bag from bonobo.structs.bags import Bag
from bonobo.util.errors import print_error
class ExecutorStrategy(Strategy): class ExecutorStrategy(Strategy):
@ -47,16 +51,16 @@ class ExecutorStrategy(Strategy):
def _runner(): def _runner():
try: try:
node.start() node.start()
except Exception as exc: except Exception:
print_error(exc, traceback.format_exc(), context=node, method='start') mondrian.excepthook(*sys.exc_info(), context='Could not start node {}.'.format(get_name(node)))
node.input.on_end() node.input.on_end()
else: else:
node.loop() node.loop()
try: try:
node.stop() node.stop()
except Exception as exc: except Exception:
print_error(exc, traceback.format_exc(), context=node, method='stop') mondrian.excepthook(*sys.exc_info(), context='Could not stop node {}.'.format(get_name(node)))
futures.append(executor.submit(_runner)) futures.append(executor.submit(_runner))
@ -68,8 +72,8 @@ class ExecutorStrategy(Strategy):
with plugin: with plugin:
try: try:
plugin.loop() plugin.loop()
except Exception as exc: except Exception:
print_error(exc, traceback.format_exc(), context=plugin) mondrian.excepthook(*sys.exc_info(), context='In plugin loop for {}...'.format(get_name(plugin)))
futures.append(executor.submit(_runner)) futures.append(executor.submit(_runner))

View File

@ -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)