Fix output in case of failed command

This commit is contained in:
jpic 2021-04-24 13:35:29 +02:00
parent 9846425b29
commit 44dd1bc6a6
2 changed files with 20 additions and 10 deletions

View File

@ -60,9 +60,13 @@ class Command(cli2.Command):
except ProcFailure: except ProcFailure:
# just output the failure without TB, as command was already # just output the failure without TB, as command was already
# printed anyway # printed anyway
pass self.exit_code = 1
self['target'].value.output.results(self['target'].value) self['target'].value.output.results(self['target'].value)
return result
if result and result.status == 'success':
self.exit_code = 0
else:
self.exit_code = 1
class ActionCommand(cli2.Command): class ActionCommand(cli2.Command):

View File

@ -6,7 +6,7 @@ import re
import sys import sys
from ..output import Output from ..output import Output
from ..proc import Proc from ..proc import Proc, ProcFailure
from ..result import Result, Results from ..result import Result, Results
@ -68,13 +68,19 @@ class Target:
self.output.fail(action, e) self.output.fail(action, e)
result.status = 'failure' result.status = 'failure'
result.exception = e result.exception = e
if reraise:
# nested call, re-raise if not isinstance(e, ProcFailure):
raise # no need to reraise in case of command error
else: # because the command has been printed
import traceback
traceback.print_exception(type(e), e, sys.exc_info()[2]) if reraise:
return True # nested call, re-raise
raise
else:
import traceback
traceback.print_exception(type(e), e, sys.exc_info()[2])
return True # because it failed
else: else:
if getattr(action, 'skipped', False): if getattr(action, 'skipped', False):
self.output.skip(action) self.output.skip(action)