mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Make yaml config parser errors look less like bugs. (#1776)
Instead of nested tracebacks, show a simpler error message. Config directory: /home/user/.homeassistant ERROR:homeassistant.util.yaml:duplicate key: "script" in "/home/user/.homeassistant/configuration.yaml", line 95, column 0 in "/home/user/.homeassistant/configuration.yaml", line 108, column 0
This commit is contained in:
parent
b87e2437aa
commit
73859f59f0
@ -22,6 +22,7 @@ from homeassistant.const import (
|
||||
CONF_CUSTOMIZE, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME,
|
||||
CONF_TEMPERATURE_UNIT, CONF_TIME_ZONE, EVENT_COMPONENT_LOADED,
|
||||
TEMP_CELCIUS, TEMP_FAHRENHEIT, PLATFORM_FORMAT, __version__)
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import (
|
||||
event_decorators, service, config_per_platform, extract_domain_configs)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
@ -293,7 +294,10 @@ def from_config_file(config_path, hass=None, verbose=False, daemon=False,
|
||||
|
||||
enable_logging(hass, verbose, daemon, log_rotate_days)
|
||||
|
||||
config_dict = config_util.load_yaml_config_file(config_path)
|
||||
try:
|
||||
config_dict = config_util.load_yaml_config_file(config_path)
|
||||
except HomeAssistantError:
|
||||
return None
|
||||
|
||||
return from_config_dict(config_dict, hass, enable_log=False,
|
||||
skip_pip=skip_pip)
|
||||
|
@ -29,10 +29,9 @@ def load_yaml(fname):
|
||||
# If configuration file is empty YAML returns None
|
||||
# We convert that to an empty dict
|
||||
return yaml.load(conf_file, Loader=SafeLineLoader) or {}
|
||||
except yaml.YAMLError:
|
||||
error = 'Error reading YAML configuration file {}'.format(fname)
|
||||
_LOGGER.exception(error)
|
||||
raise HomeAssistantError(error)
|
||||
except yaml.YAMLError as exc:
|
||||
_LOGGER.error(exc)
|
||||
raise HomeAssistantError(exc)
|
||||
|
||||
|
||||
def _include_yaml(loader, node):
|
||||
@ -55,9 +54,12 @@ def _ordered_dict(loader, node):
|
||||
line = getattr(node, '__line__', 'unknown')
|
||||
if key in seen:
|
||||
fname = getattr(loader.stream, 'name', '')
|
||||
raise yaml.YAMLError("ERROR: duplicate key: \"{}\""
|
||||
" in {} line {} and {}"
|
||||
.format(key, fname, seen[key], line))
|
||||
first_mark = yaml.Mark(fname, 0, seen[key], -1, None, None)
|
||||
second_mark = yaml.Mark(fname, 0, line, -1, None, None)
|
||||
raise yaml.MarkedYAMLError(
|
||||
context="duplicate key: \"{}\"".format(key),
|
||||
context_mark=first_mark, problem_mark=second_mark,
|
||||
)
|
||||
seen[key] = line
|
||||
|
||||
return OrderedDict(nodes)
|
||||
|
Loading…
x
Reference in New Issue
Block a user