From c2b4740029ed0660efea82e7042e0d7cb9134b10 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Mon, 16 Dec 2024 11:30:24 +0100 Subject: [PATCH 1/3] graceful error when failing to load invalid yml --- .../schemacode/src/bidsschematools/types/namespace.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/schemacode/src/bidsschematools/types/namespace.py b/tools/schemacode/src/bidsschematools/types/namespace.py index e2c37eee40..73b06ed060 100644 --- a/tools/schemacode/src/bidsschematools/types/namespace.py +++ b/tools/schemacode/src/bidsschematools/types/namespace.py @@ -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 From 383a64ecbd5863cdbafe48e9578c2e8e121d2925 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Mon, 16 Dec 2024 11:37:51 +0100 Subject: [PATCH 2/3] fail build on macro fails --- mkdocs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/mkdocs.yml b/mkdocs.yml index 08fd23ef68..d0738c7e29 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -116,6 +116,7 @@ plugins: - css/watermark.css - macros: module_name: tools/mkdocs_macros_bids/main + on_error_fail: true - redirects: redirect_maps: "01-introduction.md": "introduction.md" From 76ccc4dbaeaedf0275587bd319d63fdc58d00ac8 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Tue, 17 Dec 2024 10:48:33 +0100 Subject: [PATCH 3/3] Update tools/schemacode/src/bidsschematools/types/namespace.py Co-authored-by: Chris Markiewicz --- .../src/bidsschematools/types/namespace.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/schemacode/src/bidsschematools/types/namespace.py b/tools/schemacode/src/bidsschematools/types/namespace.py index 73b06ed060..52f21e2d0c 100644 --- a/tools/schemacode/src/bidsschematools/types/namespace.py +++ b/tools/schemacode/src/bidsschematools/types/namespace.py @@ -272,13 +272,13 @@ def from_json(cls, jsonstr: str): def _read_yaml_dir(path: Path) -> dict: mapping = {} for subpath in sorted(path.iterdir()): - try: - if subpath.is_dir(): - mapping[subpath.name] = _read_yaml_dir(subpath) - elif subpath.name.endswith("yaml"): + if subpath.is_dir(): + mapping[subpath.name] = _read_yaml_dir(subpath) + elif subpath.name.endswith("yaml"): + try: 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 + except Exception as e: + raise ValueError(f"There was an error reading the file: {subpath}") from e return mapping