Add orig_exc context to error messages (#72677)

* Add orig_exc context to error messages. Fixes #68605

* Fix string formatting
pull/72696/head
Matt Martz 4 years ago committed by GitHub
parent fb092a82a1
commit 46198cf80a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
minor_changes:
- Errors - Ensure that errors passed with ``orig_exc`` include the context of that exception
(https://github.com/ansible/ansible/issues/68605)

@ -57,9 +57,7 @@ class AnsibleError(Exception):
self._suppress_extended_error = suppress_extended_error
self._message = to_native(message)
self.obj = obj
if orig_exc:
self.orig_exc = orig_exc
self.orig_exc = orig_exc
@property
def message(self):
@ -67,11 +65,17 @@ class AnsibleError(Exception):
# since the objects code also imports ansible.errors
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject
message = [self._message]
if isinstance(self.obj, AnsibleBaseYAMLObject):
extended_error = self._get_extended_error()
if extended_error and not self._suppress_extended_error:
return '%s\n\n%s' % (self._message, to_native(extended_error))
return self._message
message.append(
'\n\n%s' % to_native(extended_error)
)
elif self.orig_exc:
message.append('. %s' % to_native(self.orig_exc))
return ''.join(message)
@message.setter
def message(self, val):

Loading…
Cancel
Save