Skip to content

Commit

Permalink
graceful error when failing to load invalid yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Dec 16, 2024
1 parent 46d2399 commit c2b4740
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tools/schemacode/src/bidsschematools/types/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,13 @@ def from_json(cls, jsonstr: str):
def _read_yaml_dir(path: Path) -> dict:
mapping = {}
for subpath in sorted(path.iterdir()):
if subpath.is_dir():
mapping[subpath.name] = _read_yaml_dir(subpath)
elif subpath.name.endswith("yaml"):
mapping[subpath.stem] = yaml.safe_load(subpath.read_text())
try:
if subpath.is_dir():
mapping[subpath.name] = _read_yaml_dir(subpath)
elif subpath.name.endswith("yaml"):
mapping[subpath.stem] = yaml.safe_load(subpath.read_text())
except Exception as e:
raise ValueError(f"There was an error reading the file: {subpath}") from e
return mapping


Expand Down

0 comments on commit c2b4740

Please sign in to comment.