mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 06:10:22 -07: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 jinja2.utils import missing
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleError
|
||||||
from ansible.module_utils.six import iteritems
|
from ansible.module_utils.six import iteritems
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
|
@ -105,10 +106,10 @@ class AnsibleJ2Vars(Mapping):
|
||||||
try:
|
try:
|
||||||
value = self._templar.template(variable)
|
value = self._templar.template(variable)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
try:
|
msg = getattr(e, 'message') or to_native(e)
|
||||||
raise type(e)(to_native(variable) + ': ' + e.message)
|
raise AnsibleError("An unhandled exception occurred while templating '%s'. "
|
||||||
except AttributeError:
|
"Error was a %s, original message: %s" % (to_native(variable), type(e), msg))
|
||||||
raise type(e)(to_native(variable) + ': ' + to_native(e))
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def add_locals(self, locals):
|
def add_locals(self, locals):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue