Do not crash callbacks if exception is not a string. (#77781)

pull/78013/head
Felix Fontein 2 years ago committed by GitHub
parent 5f5c4ef2ef
commit 570379ef98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- "callback plugins - do not crash when ``exception`` passed from a module is not a string (https://github.com/ansible/ansible/issues/75726, https://github.com/ansible/ansible/pull/77781)."

@ -299,12 +299,13 @@ class CallbackBase(AnsiblePlugin):
if 'exception' in result: if 'exception' in result:
msg = "An exception occurred during task execution. " msg = "An exception occurred during task execution. "
exception_str = to_text(result['exception'])
if self._display.verbosity < 3: if self._display.verbosity < 3:
# extract just the actual error message from the exception text # extract just the actual error message from the exception text
error = result['exception'].strip().split('\n')[-1] error = exception_str.strip().split('\n')[-1]
msg += "To see the full traceback, use -vvv. The error was: %s" % error msg += "To see the full traceback, use -vvv. The error was: %s" % error
else: else:
msg = "The full traceback is:\n" + result['exception'] msg = "The full traceback is:\n" + exception_str
del result['exception'] del result['exception']
self._display.display(msg, color=C.COLOR_ERROR, stderr=use_stderr) self._display.display(msg, color=C.COLOR_ERROR, stderr=use_stderr)

Loading…
Cancel
Save