mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-28 03:49:09 -07:00
Fix error reporting on bad type for config setting
This commit is contained in:
parent
c1400ce909
commit
c86fd6e2df
5 changed files with 28 additions and 17 deletions
|
@ -60,7 +60,7 @@ def ensure_type(value, value_type, origin=None):
|
|||
if value_type in ('boolean', 'bool'):
|
||||
value = boolean(value, strict=False)
|
||||
|
||||
elif value:
|
||||
elif value is not None:
|
||||
if value_type in ('integer', 'int'):
|
||||
value = int(value)
|
||||
|
||||
|
@ -166,7 +166,7 @@ def find_ini_config_file():
|
|||
|
||||
class ConfigManager(object):
|
||||
|
||||
UNABLE = []
|
||||
UNABLE = {}
|
||||
DEPRECATED = []
|
||||
|
||||
def __init__(self, conf_file=None, defs_file=None):
|
||||
|
@ -281,7 +281,12 @@ class ConfigManager(object):
|
|||
|
||||
def get_config_value(self, config, cfile=None, plugin_type=None, plugin_name=None, keys=None, variables=None):
|
||||
''' wrapper '''
|
||||
value, _drop = self.get_config_value_and_origin(config, cfile=cfile, plugin_type=plugin_type, plugin_name=plugin_name, keys=keys, variables=variables)
|
||||
|
||||
try:
|
||||
value, _drop = self.get_config_value_and_origin(config, cfile=cfile, plugin_type=plugin_type, plugin_name=plugin_name,
|
||||
keys=keys, variables=variables)
|
||||
except Exception as e:
|
||||
raise AnsibleError("Invalid settings supplied for %s: %s" % (config, to_native(e)))
|
||||
return value
|
||||
|
||||
def get_config_value_and_origin(self, config, cfile=None, plugin_type=None, plugin_name=None, keys=None, variables=None):
|
||||
|
@ -358,11 +363,8 @@ class ConfigManager(object):
|
|||
if plugin_type is None and isinstance(value, string_types) and (value.startswith('{{') and value.endswith('}}')):
|
||||
return value, origin
|
||||
|
||||
# ensure correct type
|
||||
try:
|
||||
value = ensure_type(value, defs[config].get('type'), origin=origin)
|
||||
except Exception as e:
|
||||
self.UNABLE.append(config)
|
||||
# ensure correct type, can raise exceptoins on mismatched types
|
||||
value = ensure_type(value, defs[config].get('type'), origin=origin)
|
||||
|
||||
# deal with deprecation of the setting
|
||||
if 'deprecated' in defs[config] and origin != 'default':
|
||||
|
@ -401,7 +403,13 @@ class ConfigManager(object):
|
|||
raise AnsibleOptionsError("Invalid configuration definition '%s': type is %s" % (to_native(config), type(defs[config])))
|
||||
|
||||
# get value and origin
|
||||
value, origin = self.get_config_value_and_origin(config, configfile)
|
||||
try:
|
||||
value, origin = self.get_config_value_and_origin(config, configfile)
|
||||
except Exception as e:
|
||||
# when building constants.py we ignore invalid configs
|
||||
# CLI takes care of warnings once 'display' is loaded
|
||||
self.UNABLE[config] = to_text(e)
|
||||
continue
|
||||
|
||||
# set the constant
|
||||
self.data.update_setting(Setting(config, value, origin, defs[config].get('type', 'string')))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue