From 9e0c207650bbbf6bb1a6530c3203d416b47ade89 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sun, 18 Oct 2009 05:17:07 +0500 Subject: modulemanager: Module loading rewritten to gracefully deal with errors in module initialization. --- core/modulemanager.lua | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'core') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index dea6860b..88d07f43 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -135,28 +135,32 @@ function load(host, module_name, config) log("debug", "Created new component: %s", host); end hosts[host].modules = modulemap[host]; + modulemap[host][module_name] = pluginenv; - local success, ret = pcall(mod); - if not success then - log("error", "Error initialising module '%s': %s", module_name or "nil", ret or "nil"); - return nil, ret; - end - - if module_has_method(pluginenv, "load") then - local ok, err = call_module_method(pluginenv, "load"); - if (not ok) and err then - log("warn", "Error loading module '%s' on '%s': %s", module_name, host, err); + local success, err = pcall(mod); + if success then + if module_has_method(pluginenv, "load") then + success, err = call_module_method(pluginenv, "load"); + if not success then + log("warn", "Error loading module '%s' on '%s': %s", module_name, host, err or "nil"); + end end - end - -- Use modified host, if the module set one - modulemap[api_instance.host][module_name] = pluginenv; - - if api_instance.host == "*" and host ~= "*" then - api_instance:set_global(); + -- Use modified host, if the module set one + if api_instance.host == "*" and host ~= "*" then + modulemap[host][module_name] = nil; + modulemap["*"][module_name] = pluginenv; + api_instance:set_global(); + end + else + log("error", "Error initializing module '%s' on '%s': %s", module_name, host, err or "nil"); + end + if success then + return true; + else -- load failed, unloading + unload(api_instance.host, module_name); + return nil, err; end - - return true; end function get_module(host, name) -- cgit v1.2.3