Skip to content

Conversation

@yugui923
Copy link

Hi Belval - thanks for writing and maintaining the pdf2image package!

I created this pull request to correct a miscategorized error message and implement more robust validation logic for inputs. Specifically:

  1. "pdf_path" argument was not validated in the "pdfinfo_from_path" function
  2. Further to the lack of validation, the entire "pdfinfo_from_path" function is covered by a try-except block, which catches all OSError and then displays a PDFInfoNotInstalledError (see below).
 except OSError:
        raise PDFInfoNotInstalledError(
            "Unable to get page count. Is poppler installed and in PATH?"
        )
  1. The combination of the above two factors will lead to wrong error messages being displayed when the "pdf_path" is invalid. Instead of raising an OSError and alert the user that the "pdf_path" is invalid, the current program will display a PDFInfoNotInstalledError, and falsely alert the user to check their poppler installation.

I've added a very simple fix to this error message and added validation logic in this PR

Error message for invlid path after fix:

  File "d:\vc-memo-generator\mg-backend\.venv\Lib\site-packages\pdf2image\pdf2image.py", line 579, in pdfinfo_from_path
    raise OSError(f"PDF file not found: {pdf_path}")
OSError: PDF file not found: /peloton_presentation_may_2024.pdf

Error message for invlid path prior to fix:

  File "d:\vc-memo-generator\mg-backend\.venv\Lib\site-packages\pdf2image\pdf2image.py", line 631, in pdfinfo_from_path
    raise PDFInfoNotInstalledError(
pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant