Add orig_exc context to error messages (#72677)

* Add orig_exc context to error messages. Fixes #68605

* Fix string formatting
This commit is contained in:
Matt Martz 2020-11-19 13:40:22 -06:00 committed by GitHub
parent fb092a82a1
commit 46198cf80a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View file

@ -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)

View file

@ -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):