issue error directly when doc is malformated

This should popup a message saying "No reader engine for this file"
instead of a crash when document file is malformated.

This should fix #868.
This commit is contained in:
chrox
2014-08-29 17:17:08 +08:00
parent 233f847954
commit 2f2d9f1bf7
6 changed files with 23 additions and 17 deletions

View File

@@ -30,15 +30,13 @@ function DjvuDocument:init()
self.koptinterface = require("document/koptinterface")
self.configurable:loadDefaults(self.options)
if not validDjvuFile(self.file) then
self.error_message = "Not a valid DjVu file"
return
error("Not a valid DjVu file")
end
local ok
ok, self._document = pcall(djvu.openDocument, self.file, self.djvulibre_cache_size)
if not ok then
self.error_message = self._document -- will contain error message
return
error(self._document) -- will contain error message
end
self.is_open = true
self.info.has_pages = true