Properly handle lack of stdout in results in v2

Fixes #10549
This commit is contained in:
James Cammarata 2015-04-21 09:48:13 -05:00
parent 351591fb80
commit c58aaf72fc

View file

@ -412,22 +412,22 @@ class ActionBase:
cmd2 = self._shell.remove(tmp, recurse=True) cmd2 = self._shell.remove(tmp, recurse=True)
self._low_level_execute_command(cmd2, tmp, sudoable=False) self._low_level_execute_command(cmd2, tmp, sudoable=False)
# FIXME: in error situations, the stdout may not contain valid data, so we try:
# should check for bad rc codes better to catch this here data = json.loads(self._filter_leading_non_json_lines(res.get('stdout', '')))
if 'stdout' in res and res['stdout'].strip(): except ValueError:
try: # not valid json, lets try to capture error
data = json.loads(self._filter_leading_non_json_lines(res['stdout'])) data = dict(failed=True, parsed=False)
except ValueError: if 'stderr' in res and res['stderr'].startswith('Traceback'):
# not valid json, lets try to capture error data['traceback'] = res['stderr']
data = {'traceback': res['stdout']} else:
if 'parsed' in data and data['parsed'] == False: data['msg'] = res.get('stdout', '')
data['msg'] += res['stderr'] if 'stderr' in res:
# pre-split stdout into lines, if stdout is in the data and there data['msg'] += res['stderr']
# isn't already a stdout_lines value there
if 'stdout' in data and 'stdout_lines' not in data: # pre-split stdout into lines, if stdout is in the data and there
data['stdout_lines'] = data.get('stdout', '').splitlines() # isn't already a stdout_lines value there
else: if 'stdout' in data and 'stdout_lines' not in data:
data = dict() data['stdout_lines'] = data.get('stdout', '').splitlines()
# store the module invocation details back into the result # store the module invocation details back into the result
data['invocation'] = dict( data['invocation'] = dict(