Log errors when loading yaml (#6257)

This commit is contained in:
Johann Kellerman 2017-03-01 06:56:23 +02:00 committed by GitHub
parent a0256e1947
commit ac49298c8d
4 changed files with 25 additions and 9 deletions

View file

@ -428,7 +428,8 @@ def async_from_config_file(config_path: str,
try:
config_dict = yield from hass.loop.run_in_executor(
None, conf_util.load_yaml_config_file, config_path)
except HomeAssistantError:
except HomeAssistantError as err:
_LOGGER.error('Error loading %s: %s', config_path, err)
return None
finally:
clear_secret_cache()

View file

@ -239,7 +239,11 @@ def load_yaml_config_file(config_path):
This method needs to run in an executor.
"""
conf_dict = load_yaml(config_path)
try:
conf_dict = load_yaml(config_path)
except FileNotFoundError as err:
raise HomeAssistantError("Config file not found: {}".format(
getattr(err, 'filename', err)))
if not isinstance(conf_dict, dict):
msg = 'The configuration file {} does not contain a dictionary'.format(

View file

@ -30,6 +30,8 @@ MOCKS = {
config_util.async_log_exception),
'package_error': ("homeassistant.config._log_pkg_error",
config_util._log_pkg_error),
'logger_exception': ("homeassistant.bootstrap._LOGGER.error",
bootstrap._LOGGER.error),
}
SILENCE = (
'homeassistant.bootstrap.clear_secret_cache',
@ -180,9 +182,9 @@ def check(config_path):
if module is None:
# Ensure list
res['except'][ERROR_STR] = res['except'].get(ERROR_STR, [])
res['except'][ERROR_STR].append('{} not found: {}'.format(
'Platform' if '.' in comp_name else 'Component', comp_name))
msg = '{} not found: {}'.format(
'Platform' if '.' in comp_name else 'Component', comp_name)
res['except'].setdefault(ERROR_STR, []).append(msg)
return None
# Test if platform/component and overwrite setup
@ -224,6 +226,11 @@ def check(config_path):
res['except'][pkg_key] = config.get('homeassistant', {}) \
.get('packages', {}).get(package)
def mock_logger_exception(msg, *params):
"""Log logger.exceptions."""
res['except'].setdefault(ERROR_STR, []).append(msg % params)
MOCKS['logger_exception'][1](msg, *params)
# Patches to skip functions
for sil in SILENCE:
PATCHES[sil] = patch(sil)

View file

@ -85,6 +85,7 @@ class TestCheckConfig(unittest.TestCase):
change_yaml_files(res)
self.assertDictEqual({}, res['components'])
res['except'].pop(check_config.ERROR_STR)
self.assertDictEqual(
{'http': {'password': 'err123'}},
res['except']
@ -111,6 +112,7 @@ class TestCheckConfig(unittest.TestCase):
'light': []},
res['components']
)
res['except'].pop(check_config.ERROR_STR)
self.assertDictEqual(
{'light.mqtt_json': {'platform': 'mqtt_json'}},
res['except']
@ -138,10 +140,12 @@ class TestCheckConfig(unittest.TestCase):
res = check_config.check(get_test_config_dir('badplatform.yaml'))
change_yaml_files(res)
self.assertDictEqual({'light': []}, res['components'])
self.assertDictEqual({check_config.ERROR_STR:
['Platform not found: light.beer']},
res['except'])
assert res['components'] == {'light': []}
assert res['except'] == {
check_config.ERROR_STR: [
'Platform not found: light.beer',
'Unable to find platform light.beer'
]}
self.assertDictEqual({}, res['secret_cache'])
self.assertDictEqual({}, res['secrets'])
self.assertListEqual(['.../badplatform.yaml'], res['yaml_files'])