Skip to content
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

Silently ignore pingImage failure and load number of pages lazily #187

Merged
merged 2 commits into from
Mar 8, 2022

Conversation

bobvandevijver
Copy link
Contributor

For some reason, pingImage fails for me when I try to convert a small pdf (latex generated formula), with the general message "Failed to read the file". However, when the pingImage method is not used or its exception catched, the conversion completes just fine for me. As it has been added as speedup only in b0d7ab0, I am confident we can safely ignore its failure. If something really is wrong, it will throw later anyways.

That is why I propose to silently catch the pingImage method, but also to move the whole number of page retrieval outside of the constructor. Its result value is never used until explicitly called using either setPage, getNumberOfPages or saveAllPagesAsImages. So, why retrieve it when it might not even be used?

Note that this might be considered BC-incompatible: I changed the $numberOfPages class property to private, to enforce the usage of the already existing getter method, which triggers the lazy load.

@freekmurze freekmurze merged commit 58df527 into spatie:main Mar 8, 2022
@freekmurze
Copy link
Member

Thanks!

@bobvandevijver bobvandevijver deleted the ignore-pingimage-failure branch March 8, 2022 07:55
@freekmurze
Copy link
Member

I'm reverting this. The "it will correctly return the number of pages in pdf file" test fails because of this PR and there was an error in the logic ($pdfFile doest not exist).

For future PRs make sure that the functionality is working and all tests pass.

@bobvandevijver
Copy link
Contributor Author

Well, I was waiting for the checks to be run, but they needed to be started manually... You can just add $this-> before the $pdfFile, that should fix it.

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.

2 participants