Merge pull request #31336 from terminalmage/config-validation-logging

Improve config validation logging
This commit is contained in:
Mike Place 2016-02-22 12:34:24 -07:00
commit 7d01979898

View File

@ -730,22 +730,40 @@ def _validate_opts(opts):
if isinstance(val, VALID_OPTS[key]):
continue
else:
errors.append(err.format(key, val, type(val), 'list'))
errors.append(
err.format(key, val, type(val).__name__, 'list')
)
if isinstance(VALID_OPTS[key](), dict):
if isinstance(val, VALID_OPTS[key]):
continue
else:
errors.append(err.format(key, val, type(val), 'dict'))
errors.append(
err.format(key, val, type(val).__name__, 'dict')
)
else:
try:
VALID_OPTS[key](val)
if isinstance(val, (list, dict)):
# We'll only get here if VALID_OPTS[key] is str or
# bool, and the passed value is a list/dict. Attempting
# to run int() or float() on a list/dict will raise an
# exception, but running str() or bool() on it will
# pass despite not being the correct type.
errors.append(
err.format(
key,
val,
type(val).__name__,
VALID_OPTS[key].__name__
)
)
except ValueError:
errors.append(
err.format(key, val, type(val), VALID_OPTS[key])
err.format(key, val, type(val).__name__, VALID_OPTS[key])
)
except TypeError:
errors.append(
err.format(key, val, type(val), VALID_OPTS[key])
err.format(key, val, type(val).__name__, VALID_OPTS[key])
)
for error in errors: