Skip to content

Commit 846a42e

Browse files
committed
Improve error reporting for shell commands
Currently when a shell command fails, only the stdout is included in the error message. In some cases this is not useful because the relevant error information is in stderr. This change adds stderr to the error message so a user may have enough information to resolve the problem. Change-Id: I595f7fd1a398c453ddc7757c551625c5bfa88d3a Fixes: rhbz#1031786
1 parent aed545d commit 846a42e

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

packstack/installer/utils/shell.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ def execute(cmd, workdir=None, can_fail=True, mask_list=None,
4747
logging.debug(block_fmt % {'title': 'STDERR',
4848
'content': masked_err})
4949
if can_fail:
50-
msg = 'Failed to execute command: %s' % masked_out
50+
msg = ('Failed to execute command, '
51+
'stdout: %s\nstderr: %s' %
52+
(masked_out, masked_err))
5153
raise ExecuteRuntimeError(msg, stdout=out, stderr=err)
5254
return proc.returncode, out
5355

@@ -102,7 +104,9 @@ def execute(self, can_fail=True, mask_list=None, log=True):
102104
if re.search(pattern, err):
103105
raise NetworkError(masked_err, stdout=out, stderr=err)
104106
else:
105-
msg = 'Failed to run remote script: %s' % masked_out
107+
msg = ('Failed to run remote script, '
108+
'stdout: %s\nstderr: %s' %
109+
(masked_out, masked_err))
106110
raise ScriptRuntimeError(msg, stdout=out, stderr=err)
107111
return obj.returncode, out
108112

tests/installer/test_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ def test_shell(self):
8787
use_shell=True, mask_list=['password'])
8888
raise AssertionError('Masked execution failed.')
8989
except ExecuteRuntimeError, ex:
90-
should_be = ('Failed to execute command: mask the %s\n' % STR_MASK)
90+
should_be = ('Failed to execute command, stdout: mask the %s\n\n'
91+
'stderr: ' % STR_MASK)
9192
self.assertEqual(str(ex), should_be)
9293

9394
script = ScriptRunner()

0 commit comments

Comments
 (0)