aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2009-10-18 05:17:07 +0500
committerWaqas Hussain <waqas20@gmail.com>2009-10-18 05:17:07 +0500
commit9e0c207650bbbf6bb1a6530c3203d416b47ade89 (patch)
tree1824b981c764bc71d28e4c5689736f1c1fa5e853 /core
parent4b7031b383c5eb046a3f48fc722a2d5430a82d24 (diff)
downloadprosody-9e0c207650bbbf6bb1a6530c3203d416b47ade89.tar.gz
prosody-9e0c207650bbbf6bb1a6530c3203d416b47ade89.zip
modulemanager: Module loading rewritten to gracefully deal with errors in module initialization.
Diffstat (limited to 'core')
-rw-r--r--core/modulemanager.lua40
1 files changed, 22 insertions, 18 deletions
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)