From 138d96f5877e3642925363534f53509628e42fcb Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 13 Dec 2019 13:39:07 +0100 Subject: [PATCH] Reformatting output of error message on execution --- lib/cr_tf/handler.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/cr_tf/handler.py b/lib/cr_tf/handler.py index 36d6f42..f361556 100644 --- a/lib/cr_tf/handler.py +++ b/lib/cr_tf/handler.py @@ -60,7 +60,7 @@ from .terraform.disk import TerraformDisk from .xlate import XLATOR -__version__ = '3.3.2' +__version__ = '3.3.3' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -2806,13 +2806,11 @@ class CreateTerraformHandler(BaseHandler): result = self.run( cmd, may_simulate=True, timeout=tf_timeout, stdout=PIPE, stderr=PIPE, check=True) except CalledProcessError as e: - msg = _("Error on executing {cmd!r}: return value {v}.").format( - cmd=e.cmd, v=e.returncode) if e.stdout: - msg += '\nOutput: {}'.format(e.stdout) + print(self.colored("Output", 'AQUA') + ':\n' + to_str(e.stdout)) if e.stderr: - msg += '\nError message: {}'.format(e.stderr) - raise ExpectedHandlerError(msg) + print(self.colored("Error message", ('BOLD', 'RED') + ':\n' + to_str(e.stderr)) + raise ExpectedHandlerError(str(e)) LOG.debug(_("Completed process:") + "\n" + str(result)) if self.existing_vms: @@ -2834,8 +2832,6 @@ class CreateTerraformHandler(BaseHandler): cmd, may_simulate=True, timeout=tf_timeout, stdout=PIPE, stderr=PIPE, check=True) except CalledProcessError as e: -# msg = _("Error on executing {cmd!r}: return value {v}.").format( -# cmd=e.cmd, v=e.returncode) if e.stdout: print(self.colored("Output", 'AQUA') + ':\n' + to_str(e.stdout)) if e.stderr: @@ -2853,13 +2849,11 @@ class CreateTerraformHandler(BaseHandler): result = self.run( cmd, may_simulate=True, timeout=tf_timeout, stdout=PIPE, stderr=PIPE, check=True) except CalledProcessError as e: - msg = _("Error on executing {cmd!r}: return value {v}.").format( - cmd=e.cmd, v=e.returncode) if e.stdout: - msg += '\nOutput: {}'.format(e.stdout) + print(self.colored("Output", 'AQUA') + ':\n' + to_str(e.stdout)) if e.stderr: - msg += '\nError message: {}'.format(e.stderr) - raise ExpectedHandlerError(msg) + print(self.colored("Error message", ('BOLD', 'RED') + ':\n' + to_str(e.stderr)) + raise ExpectedHandlerError(str(e)) LOG.debug(_("Completed process:") + "\n" + str(result)) goto = Path(os.path.relpath(self.project_dir, self.start_dir)) -- 2.39.5