plugin(fix): catch plugin crash at init time

This commit is contained in:
Qingping Hou
2017-04-20 23:37:04 -07:00
parent 16192d2354
commit fd862f5e28
3 changed files with 31 additions and 10 deletions

View File

@@ -68,4 +68,14 @@ function PluginLoader:loadPlugins()
return self.plugins
end
function PluginLoader:createPluginInstance(plugin, attr)
local ok, re = pcall(plugin.new, plugin, attr)
if ok then -- re is a plugin instance
return ok, re
else -- re is the error message
logger.err('Failed to initialize', plugin.name, 'plugin: ', re)
return nil, re
end
end
return PluginLoader