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:
parent
fb092a82a1
commit
46198cf80a
2 changed files with 12 additions and 5 deletions
|
@ -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._suppress_extended_error = suppress_extended_error
|
||||||
self._message = to_native(message)
|
self._message = to_native(message)
|
||||||
self.obj = obj
|
self.obj = obj
|
||||||
|
self.orig_exc = orig_exc
|
||||||
if orig_exc:
|
|
||||||
self.orig_exc = orig_exc
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def message(self):
|
def message(self):
|
||||||
|
@ -67,11 +65,17 @@ class AnsibleError(Exception):
|
||||||
# since the objects code also imports ansible.errors
|
# since the objects code also imports ansible.errors
|
||||||
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject
|
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject
|
||||||
|
|
||||||
|
message = [self._message]
|
||||||
if isinstance(self.obj, AnsibleBaseYAMLObject):
|
if isinstance(self.obj, AnsibleBaseYAMLObject):
|
||||||
extended_error = self._get_extended_error()
|
extended_error = self._get_extended_error()
|
||||||
if extended_error and not self._suppress_extended_error:
|
if extended_error and not self._suppress_extended_error:
|
||||||
return '%s\n\n%s' % (self._message, to_native(extended_error))
|
message.append(
|
||||||
return self._message
|
'\n\n%s' % to_native(extended_error)
|
||||||
|
)
|
||||||
|
elif self.orig_exc:
|
||||||
|
message.append('. %s' % to_native(self.orig_exc))
|
||||||
|
|
||||||
|
return ''.join(message)
|
||||||
|
|
||||||
@message.setter
|
@message.setter
|
||||||
def message(self, val):
|
def message(self, val):
|
||||||
|
|
Loading…
Reference in a new issue