# tools/pdf2image_errors.py - User-facing messages for pdf2image/poppler failures.

def message_for_pdf2image_error(exc: BaseException) -> str:
    """Return a clear, actionable message when PDF→images fails (e.g. poppler missing)."""
    msg = str(exc).strip()
    lower = msg.lower()
    if "no such file" in lower or "not found" in lower or "couldn't open file" in lower:
        return f"ERROR: PDF file not found or unreadable: {msg or exc!r}"
    if "poppler" in lower or "page count" in lower or "pdftoppm" in lower:
        return (
            "PDF could not be converted to images. Poppler is required (pdf2image uses it). "
            "On macOS install with: brew install poppler. Then try the OCR again."
        )
    return f"Failed to convert PDF to images: {msg or exc!r}"
