mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Make exception printing a bit smarter
This commit is contained in:
parent
a77b58e351
commit
0d92599d18
2 changed files with 16 additions and 2 deletions
|
@ -405,7 +405,7 @@ class ActionBase:
|
||||||
# not valid json, lets try to capture error
|
# not valid json, lets try to capture error
|
||||||
data = dict(failed=True, parsed=False)
|
data = dict(failed=True, parsed=False)
|
||||||
if 'stderr' in res and res['stderr'].startswith('Traceback'):
|
if 'stderr' in res and res['stderr'].startswith('Traceback'):
|
||||||
data['traceback'] = res['stderr']
|
data['exception'] = res['stderr']
|
||||||
else:
|
else:
|
||||||
data['msg'] = res.get('stdout', '')
|
data['msg'] = res.get('stdout', '')
|
||||||
if 'stderr' in res:
|
if 'stderr' in res:
|
||||||
|
|
|
@ -37,10 +37,24 @@ class CallbackModule(CallbackBase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def v2_runner_on_failed(self, result, ignore_errors=False):
|
def v2_runner_on_failed(self, result, ignore_errors=False):
|
||||||
if 'exception' in result._result and self._display.verbosity < 3:
|
if 'exception' in result._result:
|
||||||
|
if self._display.verbosity < 3:
|
||||||
|
# extract just the actual error message from the exception text
|
||||||
|
error = result._result['exception'].strip().split('\n')[-1]
|
||||||
|
msg = "An exception occurred during task execution. To see the full traceback, use -vvv. The error was: %s" % error
|
||||||
|
else:
|
||||||
|
msg = "An exception occurred during task execution. The full traceback is:\n" + result._result['exception']
|
||||||
|
|
||||||
|
self._display.display(msg, color='red')
|
||||||
|
|
||||||
|
# finally, remove the exception from the result so it's not shown every time
|
||||||
del result._result['exception']
|
del result._result['exception']
|
||||||
|
|
||||||
self._display.display("fatal: [%s]: FAILED! => %s" % (result._host.get_name(), json.dumps(result._result, ensure_ascii=False)), color='red')
|
self._display.display("fatal: [%s]: FAILED! => %s" % (result._host.get_name(), json.dumps(result._result, ensure_ascii=False)), color='red')
|
||||||
|
|
||||||
|
if result._task.ignore_errors:
|
||||||
|
self._display.display("...ignoring")
|
||||||
|
|
||||||
def v2_runner_on_ok(self, result):
|
def v2_runner_on_ok(self, result):
|
||||||
|
|
||||||
if result._task.action == 'include':
|
if result._task.action == 'include':
|
||||||
|
|
Loading…
Add table
Reference in a new issue