Skip to content

Commit

Permalink
Avoid showing multiple tracebacks to users (#380)
Browse files Browse the repository at this point in the history
At the moment when an actor fails, two tracebacks are
thrown to the stderr. One for an actual failure in the actor
and the other (the last one) about the actor failure itself.
As the last traceback is not useful at all we shall keep only
the first one.
  • Loading branch information
Rezney authored and vinzenz committed Nov 22, 2018
1 parent 129b7be commit d93623e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
6 changes: 4 additions & 2 deletions leapp/cli/upgrade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from leapp.repository.scan import find_and_scan_repositories
from leapp.utils.audit import Execution, get_connection, get_checkpoints
from leapp.utils.clicmd import command, command_opt
from leapp.utils.output import report_errors
from leapp.utils.output import report_errors, beautify_actor_exception


def load_repositories_from(name, repo_path, manager=None):
Expand Down Expand Up @@ -91,5 +91,7 @@ def upgrade(args):
msg = 'No such Actor: {}'.format(actor_name)
logger.error(msg)
raise CommandError(msg)
workflow.run(context=context, skip_phases_until=skip_phases_until)
with beautify_actor_exception():
workflow.run(context=context, skip_phases_until=skip_phases_until)

report_errors(workflow.errors)
5 changes: 3 additions & 2 deletions leapp/snactor/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from leapp.utils.repository import requires_repository, find_repository_basedir
from leapp.logger import configure_logger
from leapp.messaging.inprocess import InProcessMessaging
from leapp.utils.output import report_errors
from leapp.utils.output import report_errors, beautify_actor_exception
from leapp.repository.scan import find_and_scan_repositories
from leapp.snactor.context import with_snactor_context

Expand Down Expand Up @@ -41,7 +41,8 @@ def cli(args):
messaging = InProcessMessaging(stored=args.save_output)
messaging.load(actor.consumes)

actor(messaging=messaging, logger=actor_logger).run()
with beautify_actor_exception():
actor(messaging=messaging, logger=actor_logger).run()

report_errors(messaging.errors())

Expand Down
7 changes: 5 additions & 2 deletions leapp/snactor/commands/workflow/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from leapp.logger import configure_logger
from leapp.utils.repository import requires_repository, find_repository_basedir
from leapp.repository.scan import find_and_scan_repositories
from leapp.utils.output import report_errors
from leapp.utils.output import report_errors, beautify_actor_exception

_LONG_DESCRIPTION = '''
Executes the given workflow.
Expand Down Expand Up @@ -49,5 +49,8 @@ def cli(params):
actor = repository.lookup_actor(actor_name)
if actor:
instance.whitelist_experimental_actor(actor)
instance.run(until_phase=params.until_phase, until_actor=params.until_actor)

with beautify_actor_exception():
instance.run(until_phase=params.until_phase, until_actor=params.until_actor)

report_errors(instance.errors)
18 changes: 18 additions & 0 deletions leapp/utils/output.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import json
import sys
from pprint import pformat
from contextlib import contextmanager

from leapp.models import ErrorModel
from leapp.exceptions import LeappRuntimeError


def _get_colors():
Expand Down Expand Up @@ -34,3 +36,19 @@ def print_error(error):
actor=model.actor))
if model.details:
print('Detail: ' + pformat(json.loads(model.details)))


@contextmanager
def beautify_actor_exception():
try:
try:
yield
except LeappRuntimeError as e:
msg = '{} - Please check the above details'.format(e.message)
sys.stderr.write('\n')
sys.stderr.write('=' * len(msg) + '\n')
sys.stderr.write(msg + '\n')
sys.stderr.write('=' * len(msg) + '\n')
sys.stderr.write('\n')
finally:
pass

0 comments on commit d93623e

Please sign in to comment.