git » alan.git » commit 07ac5fe

Gracefully skip PDF generation when pandoc engines unavailable

author Alan Dipert
2025-12-04 04:58:28 UTC
committer Alan Dipert
2025-12-04 04:58:28 UTC
parent c7add9435c20b528dddc33b350179e31a605c5a4

Gracefully skip PDF generation when pandoc engines unavailable

render_text.py +7 -4

diff --git a/render_text.py b/render_text.py
index 087d685..0c6a0a0 100644
--- a/render_text.py
+++ b/render_text.py
@@ -7,6 +7,7 @@ from typing import Dict, Any
 import subprocess
 import shutil
 import tempfile
+import sys
 
 
 def parse_args() -> argparse.Namespace:
@@ -84,7 +85,8 @@ def _write_pdf(text: str, pdf_path: str, title: str) -> None:
     """Render plain text to PDF via pandoc if available."""
     pandoc = shutil.which("pandoc")
     if not pandoc:
-        raise RuntimeError("pandoc not found; cannot render PDF.")
+        print("pandoc not found; skipping PDF generation.", file=sys.stderr)
+        return
     with tempfile.NamedTemporaryFile("w", delete=False, suffix=".txt") as tmp:
         tmp.write(f"{title}\n\n{text}")
         tmp_path = tmp.name
@@ -104,9 +106,10 @@ def _write_pdf(text: str, pdf_path: str, title: str) -> None:
             except subprocess.CalledProcessError as e:
                 last_error = e
         if last_error:
-            raise RuntimeError(
-                "pandoc could not produce PDF; install a pdf engine such as wkhtmltopdf/weasyprint/pdflatex."
-            ) from last_error
+            print(
+                "pandoc could not produce PDF; install a pdf engine such as wkhtmltopdf/weasyprint/pdflatex.",
+                file=sys.stderr,
+            )
     finally:
         try:
             import os