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

@@ -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)