aboutsummaryrefslogtreecommitdiffstats
path: root/util/error.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2020-08-28 12:51:40 +0100
committerMatthew Wild <mwild1@gmail.com>2020-08-28 12:51:40 +0100
commit5c04c5ce383eca1e9b544885c67a976251ca12db (patch)
tree635ee6cbbf7138e9597c70720906e37e3c3b55b9 /util/error.lua
parent75079963714b6633847f05d015e1adcfde11a8f6 (diff)
downloadprosody-5c04c5ce383eca1e9b544885c67a976251ca12db.tar.gz
prosody-5c04c5ce383eca1e9b544885c67a976251ca12db.zip
util.error: Add configuration for including traceback in tostring()
Diffstat (limited to 'util/error.lua')
-rw-r--r--util/error.lua14
1 files changed, 12 insertions, 2 deletions
diff --git a/util/error.lua b/util/error.lua
index b83302fa..ffdc4eec 100644
--- a/util/error.lua
+++ b/util/error.lua
@@ -1,6 +1,15 @@
+
+-- Library configuration (see configure())
+local auto_inject_traceback = false;
+local display_tracebacks = false;
+
+
local error_mt = { __name = "error" };
function error_mt:__tostring()
+ if display_tracebacks and self.context.traceback then
+ return ("error<%s:%s:%s:%s>"):format(self.type, self.condition, self.text or "", self.context.traceback);
+ end
return ("error<%s:%s:%s>"):format(self.type, self.condition, self.text or "");
end
@@ -8,9 +17,10 @@ local function is_err(e)
return getmetatable(e) == error_mt;
end
-local auto_inject_traceback = false;
-
local function configure(opt)
+ if opt.display_tracebacks ~= nil then
+ display_tracebacks = opt.display_tracebacks;
+ end
if opt.auto_inject_traceback ~= nil then
auto_inject_traceback = opt.auto_inject_traceback;
end