clean yaml error message

This commit is contained in:
Devaev Maxim
2021-04-17 17:44:48 +03:00
parent 5dea266895
commit 19c4c7d1e3
3 changed files with 11 additions and 6 deletions

View File

@@ -28,15 +28,17 @@ from typing import Any
import yaml
import yaml.nodes
from .. import tools
# =====
def load_yaml_file(path: str) -> Any:
with open(path) as yaml_file:
try:
return yaml.load(yaml_file, _YamlLoader)
except Exception:
except Exception as err:
# Reraise internal exception as standard ValueError and show the incorrect file
raise ValueError(f"Incorrect YAML syntax in file {path!r}")
raise ValueError(f"Invalid YAML in the file {path!r}:\n{tools.efmt(err)}") from None
class _YamlLoader(yaml.SafeLoader):