From 03b8c509c3d2a2ebc10ac9d9b2c1e6c12ab51244 Mon Sep 17 00:00:00 2001 From: Konstantin Fickel Date: Fri, 6 Mar 2026 07:02:10 +0100 Subject: [PATCH] fix: add error handling for missing input files Display human-readable errors when the markdown file, photo, or signature cannot be found instead of failing with a stack trace. Co-Authored-By: Claude Opus 4.5 --- main.py | 11 ++++++++++- src/cv_generator/generator.py | 12 ++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index e03d47c..b1dd1ea 100644 --- a/main.py +++ b/main.py @@ -15,7 +15,16 @@ def generate( ), ) -> None: """Generate a PDF CV from a Markdown file with YAML frontmatter.""" - result = generate_pdf(input_file, output_file) + if not input_file.exists(): + typer.echo(f"Error: Markdown file not found: {input_file}", err=True) + raise typer.Exit(1) + + try: + result = generate_pdf(input_file, output_file) + except FileNotFoundError as e: + typer.echo(f"Error: {e}", err=True) + raise typer.Exit(1) + typer.echo(f"Generated {result}") diff --git a/src/cv_generator/generator.py b/src/cv_generator/generator.py index 4fc33e9..b13ae98 100644 --- a/src/cv_generator/generator.py +++ b/src/cv_generator/generator.py @@ -17,8 +17,16 @@ def generate_pdf(input_file: Path, output_file: Path | None = None) -> Path: letter_body: str = markdown.markdown(post.content) input_dir = Path(input_file).resolve().parent - cv.photo = str(input_dir / cv.photo) - cv.signature = str(input_dir / cv.signature) + photo_path = input_dir / cv.photo + signature_path = input_dir / cv.signature + + if not photo_path.exists(): + raise FileNotFoundError(f"Photo not found: {photo_path}") + if not signature_path.exists(): + raise FileNotFoundError(f"Signature not found: {signature_path}") + + cv.photo = str(photo_path) + cv.signature = str(signature_path) env = Environment(loader=FileSystemLoader(str(SRC_DIR))) template = env.get_template("cv.html.j2")