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:
# just output the failure without TB, as command was already
# printed anyway
pass
self.exit_code = 1
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):

View File

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