mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-09-09 06:31:04 -07:00
raises ValueError exception if conditional is not parsable (#17788)
The Conditional class now raises a ValueError with message if it cannot correclty parse the passed in conditional. This makes it easier to detect issues in modules that specify conditionals.
This commit is contained in:
parent
6d78397b8b
commit
605152e61b
1 changed files with 6 additions and 1 deletions
|
@ -42,6 +42,7 @@ def to_list(val):
|
||||||
else:
|
else:
|
||||||
return list()
|
return list()
|
||||||
|
|
||||||
|
|
||||||
class FailedConditionsError(Exception):
|
class FailedConditionsError(Exception):
|
||||||
def __init__(self, msg, failed_conditions):
|
def __init__(self, msg, failed_conditions):
|
||||||
super(FailedConditionsError, self).__init__(msg)
|
super(FailedConditionsError, self).__init__(msg)
|
||||||
|
@ -192,7 +193,11 @@ class Conditional(object):
|
||||||
self.raw = conditional
|
self.raw = conditional
|
||||||
self.encoding = encoding
|
self.encoding = encoding
|
||||||
|
|
||||||
key, op, val = shlex.split(conditional)
|
try:
|
||||||
|
key, op, val = shlex.split(conditional)
|
||||||
|
except ValueError:
|
||||||
|
raise ValueError('failed to parse conditional')
|
||||||
|
|
||||||
self.key = key
|
self.key = key
|
||||||
self.func = self._func(op)
|
self.func = self._func(op)
|
||||||
self.value = self._cast_value(val)
|
self.value = self._cast_value(val)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue