mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
Try to show original exception info for yaml (and other) errors (#24468)
* show original exception for yaml (and other) errors
In places where we need to catch a yaml error and raise
an AnsibleError, add the orig yaml exc to the AnsibleError
via the orig_exc arg.
When the AnsibleError is displayed it will now include the
AnsibleError (AnsibleParserError for example) and the type
and message from the original yaml exception.
This provides more detail to the error messages related to
yaml errors.
This also improves errors from dataloader (for example,
previously if a wrong password was used for a vault encrypted
yaml file, the error was very vague and suggested yaml errors,
but now the message includes the original exception from vault
indicating the password was incorrect or missing).
Add a text note to playbook helper asserts. For playbook
syntax/layout errors that aren't yaml errors, but errors
indicating invalid data structures for a playbook/task/role/block,
we now include some info about where the assert was and
why it was raised.
In places we raise an AnsibleParserError in an except
clause, pass the original exception to AnsibleParserError via
orig_exc arg.
Make assorted error messages a little more specific (like
the playbook helper load methods)
* Revert "Include the original YAML error in syntax error messages"
This reverts commit 781bb44b02
.
This commit is contained in:
parent
ccc7f788c0
commit
4befefd78c
16 changed files with 66 additions and 60 deletions
|
@ -43,7 +43,7 @@ def load_list_of_blocks(ds, play, parent_block=None, role=None, task_include=Non
|
|||
from ansible.playbook.task_include import TaskInclude
|
||||
from ansible.playbook.role_include import IncludeRole
|
||||
|
||||
assert isinstance(ds, (list, type(None)))
|
||||
assert isinstance(ds, (list, type(None))), '%s should be a list or None but is %s' % (ds, type(ds))
|
||||
|
||||
block_list = []
|
||||
if ds:
|
||||
|
@ -89,11 +89,11 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h
|
|||
from ansible.playbook.handler_task_include import HandlerTaskInclude
|
||||
from ansible.template import Templar
|
||||
|
||||
assert isinstance(ds, list)
|
||||
assert isinstance(ds, list), 'The ds (%s) should be a list but was a %s' % (ds, type(ds))
|
||||
|
||||
task_list = []
|
||||
for task_ds in ds:
|
||||
assert isinstance(task_ds, dict)
|
||||
assert isinstance(task_ds, dict), 'The ds (%s) should be a dict but was a %s' % (ds, type(ds))
|
||||
|
||||
if 'block' in task_ds:
|
||||
t = Block.load(
|
||||
|
@ -190,7 +190,7 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h
|
|||
if not found:
|
||||
try:
|
||||
include_target = templar.template(t.args['_raw_params'])
|
||||
except AnsibleUndefinedVariable:
|
||||
except AnsibleUndefinedVariable as e:
|
||||
raise AnsibleParserError(
|
||||
"Error when evaluating variable in include name: %s.\n\n"
|
||||
"When using static includes, ensure that any variables used in their names are defined in vars/vars_files\n"
|
||||
|
@ -198,7 +198,7 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h
|
|||
"sources like group or host vars." % t.args['_raw_params'],
|
||||
obj=task_ds,
|
||||
suppress_extended_error=True,
|
||||
)
|
||||
orig_exc=e)
|
||||
if t._role:
|
||||
include_file = loader.path_dwim_relative(t._role._role_path, subdir, include_target)
|
||||
else:
|
||||
|
@ -341,7 +341,7 @@ def load_list_of_roles(ds, play, current_role_path=None, variable_manager=None,
|
|||
# we import here to prevent a circular dependency with imports
|
||||
from ansible.playbook.role.include import RoleInclude
|
||||
|
||||
assert isinstance(ds, list)
|
||||
assert isinstance(ds, list), 'ds (%s) should be a list but was a %s' % (ds, type(ds))
|
||||
|
||||
roles = []
|
||||
for role_def in ds:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue