Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add orig_exc context to error messages #72677

Merged
merged 2 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/68605-ansible-error-orig-exc-context.yml
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 9 additions & 5 deletions lib/ansible/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,25 @@ def __init__(self, message="", obj=None, show_content=True, suppress_extended_er
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):
# we import this here to prevent an import loop problem,
# 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):
Expand Down