Add error handling to !include command in yaml (#25801)

* Catch errors if !include file is not found

* Address review comments

* Add line number to error message
This commit is contained in:
Thomas Lovén 2019-08-09 22:21:08 +02:00 committed by Paulus Schoutsen
parent f58106c7b7
commit 60dfa38717

View File

@ -116,7 +116,10 @@ def _include_yaml(loader: SafeLineLoader, node: yaml.nodes.Node) -> JSON_TYPE:
"""
fname = os.path.join(os.path.dirname(loader.name), node.value)
return _add_reference(load_yaml(fname), loader, node)
try:
return _add_reference(load_yaml(fname), loader, node)
except FileNotFoundError:
raise HomeAssistantError(f"{node.start_mark}: Unable to read file {fname}.")
def _is_file_valid(name: str) -> bool: