summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tomasz@kramkow.ski>2025-08-31 18:30:42 +0100
committerTomasz Kramkowski <tomasz@kramkow.ski>2025-08-31 18:53:40 +0100
commit51ce49a6bbbd8f4348450b19193c37a84d2d03f9 (patch)
treec9f262c60059d21d724c86d0cac5ed35416fe4ce
parente585a62e82b210c05738a4a9e7a8e660c2aca522 (diff)
downloadssg-51ce49a6bbbd8f4348450b19193c37a84d2d03f9.tar.gz
ssg-51ce49a6bbbd8f4348450b19193c37a84d2d03f9.tar.xz
ssg-51ce49a6bbbd8f4348450b19193c37a84d2d03f9.zip
Exception chanining
-rw-r--r--ssg.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/ssg.py b/ssg.py
index 30e80d2..9816a41 100644
--- a/ssg.py
+++ b/ssg.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2023-2024 Tomasz Kramkowski <tomasz@kramkow.ski>
+# Copyright (C) 2023-2025 Tomasz Kramkowski <tomasz@kramkow.ski>
# SPDX-License-Identifier: MIT
"""A basic static site generator"""
@@ -71,9 +71,12 @@ class Generator:
def parse(source: str | Path) -> dict[str, Any]:
- with open(source) as f:
- toml, content = f.read().split("\n\n", maxsplit=1)
- vars = tomllib.loads(toml)
+ try:
+ with open(source) as f:
+ toml, content = f.read().split("\n\n", maxsplit=1)
+ vars = tomllib.loads(toml)
+ except (OSError, tomllib.TOMLDecodeError) as e:
+ raise ValueError("Error parsing {source}") from e
vars["content"] = content
return vars