Diff

core/modulemanager.lua @ 2977:686f9a5a7f5e

modulemanager: Log proper tracebacks on errors during module load/unload.
author Waqas Hussain <waqas20@gmail.com>
date Mon, 19 Apr 2010 18:29:10 +0500
parent 2951:294c359a05f5
child 3165:4ffb5469c1f6
line wrap: on
line diff
--- a/core/modulemanager.lua	Mon Apr 19 18:28:12 2010 +0500
+++ b/core/modulemanager.lua	Mon Apr 19 18:29:10 2010 +0500
@@ -19,7 +19,7 @@
 local hosts = hosts;
 local prosody = prosody;
 
-local loadfile, pcall = loadfile, pcall;
+local loadfile, pcall, xpcall = loadfile, pcall, xpcall;
 local setmetatable, setfenv, getfenv = setmetatable, setfenv, getfenv;
 local pairs, ipairs = pairs, ipairs;
 local t_insert, t_concat = table.insert, table.concat;
@@ -29,6 +29,14 @@
 local error = error;
 local tostring, tonumber = tostring, tonumber;
 
+local debug_traceback = debug.traceback;
+local unpack, select = unpack, select;
+pcall = function(f, ...)
+	local n = select("#", ...);
+	local params = {...};
+	return xpcall(function() f(unpack(params, 1, n)) end, function(e) return tostring(e).."\n"..debug_traceback(); end);
+end
+
 local array, set = require "util.array", require "util.set";
 
 local autoload_modules = {"presence", "message", "iq"};