baskerville / plato

Document reader
Other
1.32k stars 110 forks source link

Giving explicit information on MuPDF errors #376

Open randomnoise opened 2 months ago

randomnoise commented 2 months ago

I have an old 32 MB .cbz file that works on stock Kobo reader and on KOReader but doesn't work on Plato. Plato doesn't show preview thumbnail about the book and when I select it, nothing happens.

I've assumed this was a Plato issue because KOReader uses MuPDF on some parts and the .cbz file works on koreader application.

I looked at info.log and archive.log on Plato directory in my Kobo device, there was no information. Logs also didn't show the path of the problematic file.

At some point, I've tried mupdf-x11 and mupdf-gl with the .cbz file on my computer (MuPDF version 1.23.11), MuPDF can't open it. It turns out it is a MuPDF issue. The problem persist on the latest 1.24.9 MuPDF version too. So, upgrading the dependency won't help on this issue.

Giving some information to user or adding a line to info.log about the MuPDF errors would go a long way.

randomnoise commented 2 months ago

I wanted to open a new issue about MuPDF errors in more general terms in case further changes are needed, but also I've traced the issue between this specific .cbz file and MuPDF.

I've debugged the problem using the emulator, I can give some pointers. Problem starts here: https://github.com/baskerville/plato/blob/a6bf89211115a7246f4dfdb69484ead17e5547bd/crates/core/src/view/reader/mod.rs#L298

resolve_location calls pages_count() function that also calls MuPDF's mp_count_pages function. mp_count_pages returns 0 (although .cbz file has a lot of pages), then resolve_location swallows the issue and does not give any information: https://github.com/baskerville/plato/blob/a6bf89211115a7246f4dfdb69484ead17e5547bd/crates/core/src/document/pdf.rs#L168-L175


I wanted to try these methods and Plato with an empty text file. So, I created one with

$ touch empty.txt

and opened empty.txt in the Plato emulator. MuPDF's mp_count_pages function returns 1 and resolve_location continues its business as usual; Plato opens the empty.txt as a book with 1 empty page. Empty text file does not issue for MuPDF and Plato in this case.