Settings: add format handling to yaml exception marks for readability (#4531)

This commit is contained in:
qwint
2025-02-09 06:11:27 -05:00
committed by GitHub
parent f75a1ae117
commit f5c574c37a

View File

@@ -792,7 +792,17 @@ class Settings(Group):
if location:
from Utils import parse_yaml
with open(location, encoding="utf-8-sig") as f:
from yaml.error import MarkedYAMLError
try:
options = parse_yaml(f.read())
except MarkedYAMLError as ex:
if ex.problem_mark:
f.seek(0)
lines = f.readlines()
problem_line = lines[ex.problem_mark.line]
error_line = " " * ex.problem_mark.column + "^"
raise Exception(f"{ex.context} {ex.problem}\n{problem_line}{error_line}")
raise ex
# TODO: detect if upgrade is required
# TODO: once we have a cache for _world_settings_name_cache, detect if any game section is missing
self.update(options or {})