mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Remove incorrect assumption on exception constructors (#35271)
Do not assume that all exception constructors accept a single string argument. For example UnicodeError's __init__ takes 5 parameters: encoding, object, start, end, reason. Also, if e.message is present but empty, fall back on stringifying the exception occurrence. Fixes #35270
This commit is contained in:
parent
7404dc6767
commit
101e983f07
1 changed files with 5 additions and 4 deletions
|
@ -23,6 +23,7 @@ from collections import Mapping
|
|||
|
||||
from jinja2.utils import missing
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
@ -105,10 +106,10 @@ class AnsibleJ2Vars(Mapping):
|
|||
try:
|
||||
value = self._templar.template(variable)
|
||||
except Exception as e:
|
||||
try:
|
||||
raise type(e)(to_native(variable) + ': ' + e.message)
|
||||
except AttributeError:
|
||||
raise type(e)(to_native(variable) + ': ' + to_native(e))
|
||||
msg = getattr(e, 'message') or to_native(e)
|
||||
raise AnsibleError("An unhandled exception occurred while templating '%s'. "
|
||||
"Error was a %s, original message: %s" % (to_native(variable), type(e), msg))
|
||||
|
||||
return value
|
||||
|
||||
def add_locals(self, locals):
|
||||
|
|
Loading…
Reference in a new issue