mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
more complete and informative errors
mostly templating issues now all return data templated and actual error fixes #14781
This commit is contained in:
parent
0031a72e0d
commit
4cfd042839
1 changed files with 9 additions and 10 deletions
|
@ -40,7 +40,7 @@ from ansible.template.safe_eval import safe_eval
|
||||||
from ansible.template.template import AnsibleJ2Template
|
from ansible.template.template import AnsibleJ2Template
|
||||||
from ansible.template.vars import AnsibleJ2Vars
|
from ansible.template.vars import AnsibleJ2Vars
|
||||||
from ansible.utils.debug import debug
|
from ansible.utils.debug import debug
|
||||||
from ansible.utils.unicode import to_unicode
|
from ansible.utils.unicode import to_unicode, to_str
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
|
@ -473,10 +473,10 @@ class Templar:
|
||||||
try:
|
try:
|
||||||
t = myenv.from_string(data)
|
t = myenv.from_string(data)
|
||||||
except TemplateSyntaxError as e:
|
except TemplateSyntaxError as e:
|
||||||
raise AnsibleError("template error while templating string: %s. String: %s" % (str(e), data))
|
raise AnsibleError("template error while templating string: %s. String: %s" % (to_str(e), to_str(data)))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if 'recursion' in str(e):
|
if 'recursion' in to_str(e):
|
||||||
raise AnsibleError("recursive loop detected in template string: %s" % data)
|
raise AnsibleError("recursive loop detected in template string: %s" % to_str(data))
|
||||||
else:
|
else:
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -492,13 +492,12 @@ class Templar:
|
||||||
res = j2_concat(rf)
|
res = j2_concat(rf)
|
||||||
except TypeError as te:
|
except TypeError as te:
|
||||||
if 'StrictUndefined' in str(te):
|
if 'StrictUndefined' in str(te):
|
||||||
raise AnsibleUndefinedVariable(
|
errmsg = "Unable to look up a name or access an attribute in template string (%s).\n" % to_str(data)
|
||||||
"Unable to look up a name or access an attribute in template string. " + \
|
errmsg += "Make sure your variable name does not contain invalid characters like '-': %s" % to_str(te)
|
||||||
"Make sure your variable name does not contain invalid characters like '-'."
|
raise AnsibleUndefinedVariable(errmsg)
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
debug("failing because of a type error, template data is: %s" % data)
|
debug("failing because of a type error, template data is: %s" % to_str(data))
|
||||||
raise AnsibleError("an unexpected type error occurred. Error was %s" % te)
|
raise AnsibleError("Unexpected templating type error occurred on (%s): %s" % (to_str(data),to_str(te)))
|
||||||
|
|
||||||
if preserve_trailing_newlines:
|
if preserve_trailing_newlines:
|
||||||
# The low level calls above do not preserve the newline
|
# The low level calls above do not preserve the newline
|
||||||
|
|
Loading…
Reference in a new issue