]> danix's work - publisher.git/commitdiff
fix: narrow exception clause to ValueError/OSError, add corrupt frontmatter test
authorDanilo M. <redacted>
Sun, 3 May 2026 08:07:43 +0000 (10:07 +0200)
committerDanilo M. <redacted>
Sun, 3 May 2026 08:07:43 +0000 (10:07 +0200)
core/article_scanner.py
tests/test_article_scanner.py

index ea6579aed432be7ecfc7c953ab17136a62b64b54..bb69a26544e4ee0e722303d0850ff744cad86d5b 100644 (file)
@@ -20,7 +20,7 @@ def scan_articles(blog_root: Path) -> list[Article]:
         translation_path = by_slug.get((other_lang, slug))
         try:
             fm, _ = parse_frontmatter(path)
-        except (ValueError, Exception):
+        except (ValueError, OSError):
             fm = {}
         articles.append(Article(
             slug=slug,
index 66daf8306d263858f7da468e96c510418678e28f..db8b683054dee3e3611b08cfc5358791e02091c6 100644 (file)
@@ -33,6 +33,14 @@ def test_scan_detects_missing_translation(tmp_path):
     assert art.has_translation is False
     assert art.translation_path is None
 
+def test_scan_tolerates_corrupt_frontmatter(tmp_path):
+    p = tmp_path / "content" / "it" / "articles" / "broken"
+    p.mkdir(parents=True)
+    (p / "index.md").write_text("no frontmatter delimiters here\n")
+    articles = scan_articles(tmp_path)
+    art = next(a for a in articles if a.slug == "broken")
+    assert art.frontmatter == {}
+
 def test_scan_parses_frontmatter(tmp_path):
     _make_article(tmp_path, "it", "con-fm", 'tags = ["linux"]\n')
     articles = scan_articles(tmp_path)