-
Notifications
You must be signed in to change notification settings - Fork 556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
open stream can raise a FzErrorFormat error instead of FileDataError #3905
Comments
The difference here is that in your file case the filename suffix Where as your stream case just specifies the data with no filetype information, so PyMuPDF tries to open the stream as a PDF by default. Instead you can specify the filetype explicitly with |
Right, but my concern here is about the exception I get. From the docs, I expected I could certainly change my code to also check for For example, I have changed my code as follows: try:
...
except (pymupdf.FileDataError, KeyError) as e:
raise ValidationError(f"Unable to open file: {e}") from e
+ except pymupdf.mupdf.FzErrorBase as e:
+ # https://github.com/pymupdf/PyMuPDF/issues/3905
+ raise ValidationError(
+ f"Perhaps not a pdf file? Unexpected error: {e}"
+ ) from e |
(I have edited to issue title to try to clarify I'm asking about what sort of Exception I should get here) |
Ah, i see what you mean. The problem is that we don't wrap the internal call to I have a fix in my tree. |
…ocument_with_stream() fails. We wrap fz_open_document_with_stream(), converting exception to FileDataError; this makes things behave similarly to when we call fz_open_document(). Addresses pymupdf#3905.
…ocument_with_stream() fails. We wrap fz_open_document_with_stream(), converting exception to FileDataError; this makes things behave similarly to when we call fz_open_document(). Addresses #3905.
Fixed in 1.24.11. |
Description of the bug
If I feed a .csv file to
pymupdf.open
, I get an FileDataError, as documented:But if I instead pass the bytes of the same file to
stream=
I get anFzErrorFormat
, which I was not expecting from the docs.How to reproduce the bug
It probably doesn't matter what's in csv but here's mine:
Now we try to open this:
Contrast this with what happens when I open the file directly:
(we can see it still fails with FzErrorUnSupported but this ultimately raises FileDataError as documented).
PyMuPDF version
1.24.10
Operating system
Linux
Python version
3.12
The text was updated successfully, but these errors were encountered: