[BACKEND] Include yaml exception in error (#678)

* [BACKEND] Include yaml exception in error

* unit test

* escape
This commit is contained in:
Jesse Bannon 2023-07-29 23:05:34 -07:00 committed by GitHub
parent 5f9b8afc4b
commit 85c98f2eb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 6 deletions

View file

@ -38,9 +38,9 @@ def load_yaml(file_path: str | Path) -> Dict:
with open(file_path, "r", encoding="utf-8") as file:
output = yaml.safe_load(file)
except YAMLError as yaml_exception:
logger.debug(yaml_exception)
raise InvalidYamlException(
f"'{file_path}' has invalid YAML, copy-paste it into a YAML checker to find the issue."
f"'{file_path}' has invalid YAML:\n{yaml_exception}\n\n"
f"Copy-pasting it into a YAML parser can also help find the issue."
) from yaml_exception
if not isinstance(output, dict):

View file

@ -69,10 +69,7 @@ def test_load_yaml_file_not_found():
def test_load_yaml_invalid_syntax(bad_yaml_file_path: str):
with pytest.raises(
InvalidYamlException,
match=re.escape(
f"'{bad_yaml_file_path}' has invalid YAML, "
f"copy-paste it into a YAML checker to find the issue."
),
match=re.escape(f"'{bad_yaml_file_path}' has invalid YAML"),
):
load_yaml(file_path=bad_yaml_file_path)