From 51ce49a6bbbd8f4348450b19193c37a84d2d03f9 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sun, 31 Aug 2025 18:30:42 +0100 Subject: Exception chanining --- ssg.py | 11 +++++++---- 1 file 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 +# Copyright (C) 2023-2025 Tomasz Kramkowski # 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 -- cgit v1.2.3-70-g09d2