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: try:
config_dict = yield from hass.loop.run_in_executor( config_dict = yield from hass.loop.run_in_executor(
None, conf_util.load_yaml_config_file, config_path) 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 return None
finally: finally:
clear_secret_cache() clear_secret_cache()

View File

@ -239,7 +239,11 @@ def load_yaml_config_file(config_path):
This method needs to run in an executor. This method needs to run in an executor.
""" """
try:
conf_dict = load_yaml(config_path) 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): if not isinstance(conf_dict, dict):
msg = 'The configuration file {} does not contain a dictionary'.format( msg = 'The configuration file {} does not contain a dictionary'.format(

View File

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

View File

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