mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -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
|
@ -220,7 +220,7 @@ class Base(with_metaclass(BaseMeta, object)):
|
|||
def load_data(self, ds, variable_manager=None, loader=None):
|
||||
''' walk the input datastructure and assign any values '''
|
||||
|
||||
assert ds is not None
|
||||
assert ds is not None, 'ds (%s) should not be None but it is.' % ds
|
||||
|
||||
# cache the datastructure internally
|
||||
setattr(self, '_ds', ds)
|
||||
|
@ -440,12 +440,12 @@ class Base(with_metaclass(BaseMeta, object)):
|
|||
setattr(self, name, value)
|
||||
|
||||
except (TypeError, ValueError) as e:
|
||||
raise AnsibleParserError("the field '%s' has an invalid value (%s), and could not be converted to an %s. "
|
||||
"The error was: %s" % (name, value, attribute.isa, e), obj=self.get_ds())
|
||||
raise AnsibleParserError("the field '%s' has an invalid value (%s), and could not be converted to an %s."
|
||||
"The error was: %s" % (name, value, attribute.isa, e), obj=self.get_ds(), orig_exc=e)
|
||||
except (AnsibleUndefinedVariable, UndefinedError) as e:
|
||||
if templar._fail_on_undefined_errors and name != 'name':
|
||||
raise AnsibleParserError("the field '%s' has an invalid value, which appears to include a variable that is undefined. "
|
||||
"The error was: %s" % (name, e), obj=self.get_ds())
|
||||
raise AnsibleParserError("the field '%s' has an invalid value, which appears to include a variable that is undefined."
|
||||
"The error was: %s" % (name, e), obj=self.get_ds(), orig_exc=e)
|
||||
|
||||
self._finalized = True
|
||||
|
||||
|
@ -477,10 +477,11 @@ class Base(with_metaclass(BaseMeta, object)):
|
|||
return {}
|
||||
else:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
raise AnsibleParserError("Vars in a %s must be specified as a dictionary, or a list of dictionaries" % self.__class__.__name__, obj=ds)
|
||||
except ValueError as e:
|
||||
raise AnsibleParserError("Vars in a %s must be specified as a dictionary, or a list of dictionaries" % self.__class__.__name__,
|
||||
obj=ds, orig_exc=e)
|
||||
except TypeError as e:
|
||||
raise AnsibleParserError("Invalid variable name in vars specified for %s: %s" % (self.__class__.__name__, e), obj=ds)
|
||||
raise AnsibleParserError("Invalid variable name in vars specified for %s: %s" % (self.__class__.__name__, e), obj=ds, orig_exc=e)
|
||||
|
||||
def _extend_value(self, value, new_value, prepend=False):
|
||||
'''
|
||||
|
@ -554,7 +555,7 @@ class Base(with_metaclass(BaseMeta, object)):
|
|||
and extended.
|
||||
'''
|
||||
|
||||
assert isinstance(data, dict)
|
||||
assert isinstance(data, dict), 'data (%s) should be a dict but is a %s' % (data, type(data))
|
||||
|
||||
for (name, attribute) in iteritems(self._valid_attrs):
|
||||
if name in data:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue