mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #870 from chrox/fix_868
issue error directly when doc is malformated
This commit is contained in:
@@ -76,7 +76,6 @@ function CreDocument:init()
|
||||
self:engineInit()
|
||||
self.configurable:loadDefaults(self.options)
|
||||
|
||||
local ok
|
||||
local file_type = string.lower(string.match(self.file, ".+%.([^.]+)"))
|
||||
if file_type == "zip" then
|
||||
-- NuPogodi, 20.05.12: read the content of zip-file
|
||||
@@ -95,12 +94,12 @@ function CreDocument:init()
|
||||
|
||||
-- @TODO check the default view_mode to a global user configurable
|
||||
-- variable 22.12 2012 (houqp)
|
||||
local ok
|
||||
ok, self._document = pcall(cre.newDocView,
|
||||
Screen:getWidth(), Screen:getHeight(), self.PAGE_VIEW_MODE
|
||||
)
|
||||
if not ok then
|
||||
self.error_message = self._document -- will contain error message
|
||||
return
|
||||
error(self._document) -- will contain error message
|
||||
end
|
||||
|
||||
-- adjust font sizes according to screen dpi
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -24,7 +24,6 @@ local Document = {
|
||||
|
||||
-- flag to show whether the document was opened successfully
|
||||
is_open = false,
|
||||
error_message = nil,
|
||||
|
||||
-- flag to show that the document needs to be unlocked by a password
|
||||
is_locked = false,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
local DEBUG = require("dbg")
|
||||
|
||||
--[[
|
||||
This is a registry for document providers
|
||||
]]--
|
||||
@@ -24,15 +26,22 @@ function DocumentRegistry:openDocument(file)
|
||||
if not self.registry[file] then
|
||||
local provider = self:getProvider(file)
|
||||
if provider ~= nil then
|
||||
self.registry[file] = {
|
||||
doc = provider:new{file = file},
|
||||
refs = 1,
|
||||
}
|
||||
local ok, doc = pcall(provider.new, provider, {file = file})
|
||||
if ok then
|
||||
self.registry[file] = {
|
||||
doc = doc,
|
||||
refs = 1,
|
||||
}
|
||||
else
|
||||
DEBUG("cannot open document", file, doc)
|
||||
end
|
||||
end
|
||||
else
|
||||
self.registry[file].refs = self.registry[file].refs + 1
|
||||
end
|
||||
return self.registry[file].doc
|
||||
if self.registry[file] then
|
||||
return self.registry[file].doc
|
||||
end
|
||||
end
|
||||
|
||||
function DocumentRegistry:closeDocument(file)
|
||||
|
||||
@@ -56,8 +56,7 @@ function PdfDocument:init()
|
||||
local ok
|
||||
ok, self._document = pcall(pdf.openDocument, self.file, self.mupdf_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
|
||||
@@ -67,6 +66,9 @@ function PdfDocument:init()
|
||||
else
|
||||
self:_readMetadata()
|
||||
end
|
||||
if not (self.info.number_of_pages > 0) then
|
||||
error("No page found in PDF file")
|
||||
end
|
||||
end
|
||||
|
||||
function PdfDocument:unlock(password)
|
||||
|
||||
@@ -11,8 +11,7 @@ function PicDocument:init()
|
||||
if not pic then pic = require("ffi/pic") end
|
||||
ok, self._document = pcall(pic.openDocument, self.file)
|
||||
if not ok then
|
||||
self.error_message = "failed to open jpeg image"
|
||||
return
|
||||
error("Failed to open jpeg image")
|
||||
end
|
||||
|
||||
self.info.has_pages = true
|
||||
|
||||
Reference in New Issue
Block a user