From 02395c5d1d6296e096724247e727756feebccd7d Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Mon, 9 Nov 2026 16:01:16 +0200 Subject: [PATCH 1/2] Report any frontmatter PyYAML rejects as invalid YAML `_frontmatter` turns a YAMLError into a structural error for its skill, but PyYAML does not raise one for everything it rejects: a timestamp that is no date (`2001-13-45`) raises ValueError, a tag whose value it cannot construct raises AttributeError (`!!timestamp x`) or KeyError (`!!bool x`), and nesting deeper than the interpreter allows raises RecursionError. Each ended the structural check with a traceback instead of reporting the skill. `safe_load` of a string does nothing else that can fail, so every exception it raises is the frontmatter's, and is reported as "frontmatter is not valid YAML". Signed-off-by: Roman Inflianskas --- skillscope/structure.py | 6 +++++- tests/test_skillscope.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/skillscope/structure.py b/skillscope/structure.py index 171eaf5..4740b5b 100644 --- a/skillscope/structure.py +++ b/skillscope/structure.py @@ -143,9 +143,13 @@ def _frontmatter(text: str) -> tuple[dict | None, str, str]: import yaml # noqa: PLC0415 -- keeps the run path stdlib-only + # Any exception, not only YAMLError: PyYAML rejects some input with + # ValueError, AttributeError or KeyError (a tag whose value it cannot + # construct, such as `!!timestamp x`), and deep nesting raises + # RecursionError. `safe_load` of a string does nothing else that can fail. try: declared = yaml.safe_load(match.group("frontmatter")) - except yaml.YAMLError as exc: + except Exception as exc: # noqa: BLE001 -- every rejection is the file's return None, "", f"frontmatter is not valid YAML: {exc}" if not isinstance(declared, dict): return None, "", ( diff --git a/tests/test_skillscope.py b/tests/test_skillscope.py index 5d4cf7b..e950be4 100644 --- a/tests/test_skillscope.py +++ b/tests/test_skillscope.py @@ -1610,6 +1610,23 @@ def test_frontmatter_that_is_not_yaml_is_reported_as_such(self) -> None: self.declares("name: [demo-skill\ndescription: broken") self.assertTrue(any("not valid YAML" in e for e in structure.errors())) + def test_yaml_the_parser_rejects_without_a_yaml_error_is_reported_too(self) -> None: + # Each of these is rejected with something other than a YAMLError: + # ValueError, AttributeError, KeyError, and RecursionError for nesting + # deeper than the interpreter allows. Each used to end the structural + # check with a traceback. + for name, frontmatter in ( + ("date", "name: demo-skill\ndescription: d\nupdated: 2001-13-45"), + ("timestamp tag", "name: demo-skill\ndescription: d\nupdated: !!timestamp x"), + ("bool tag", "name: demo-skill\ndescription: d\ndraft: !!bool x"), + ("nesting", "name: demo-skill\ndescription: " + "[" * 2_000), + ): + with self.subTest(name): + self.declares(frontmatter) + errors = structure.errors() + self.assertEqual(len(errors), 1, errors) + self.assertIn("not valid YAML", errors[0]) + def test_frontmatter_that_is_not_a_mapping_is_reported(self) -> None: self.declares("- demo-skill\n- a list, not a mapping") self.assertTrue(any("must be a mapping" in e for e in structure.errors())) From b1f9b50d2e5605d317e4e4aaaa85d62bac198257 Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Wed, 11 Nov 2026 12:42:44 +0200 Subject: [PATCH 2/2] Finish the reason given for the broad except "every rejection is the file's" read as a sentence cut off mid-edit. Say outright that whatever safe_load raises is the frontmatter's fault. Signed-off-by: Roman Inflianskas --- skillscope/structure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skillscope/structure.py b/skillscope/structure.py index 4740b5b..9bba866 100644 --- a/skillscope/structure.py +++ b/skillscope/structure.py @@ -149,7 +149,7 @@ def _frontmatter(text: str) -> tuple[dict | None, str, str]: # RecursionError. `safe_load` of a string does nothing else that can fail. try: declared = yaml.safe_load(match.group("frontmatter")) - except Exception as exc: # noqa: BLE001 -- every rejection is the file's + except Exception as exc: # noqa: BLE001 -- whatever safe_load raises is the frontmatter's fault return None, "", f"frontmatter is not valid YAML: {exc}" if not isinstance(declared, dict): return None, "", (