diff options
author | Matthew Wild <mwild1@gmail.com> | 2020-08-28 12:40:59 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2020-08-28 12:40:59 +0100 |
commit | 75079963714b6633847f05d015e1adcfde11a8f6 (patch) | |
tree | 49dea77a4374620ae7617ec9e488b026e23d366f /util | |
parent | c340e3ab373d32fd909e5902538031ed30d9585f (diff) | |
download | prosody-75079963714b6633847f05d015e1adcfde11a8f6.tar.gz prosody-75079963714b6633847f05d015e1adcfde11a8f6.zip |
util.error: Allow optional tracebacks to be injected on errors
This allows extra debug info to be provided for development purposes.
Diffstat (limited to 'util')
-rw-r--r-- | util/error.lua | 15 | ||||
-rw-r--r-- | util/startup.lua | 6 |
2 files changed, 21 insertions, 0 deletions
diff --git a/util/error.lua b/util/error.lua index ca960dd9..b83302fa 100644 --- a/util/error.lua +++ b/util/error.lua @@ -8,6 +8,14 @@ local function is_err(e) return getmetatable(e) == error_mt; end +local auto_inject_traceback = false; + +local function configure(opt) + if opt.auto_inject_traceback ~= nil then + auto_inject_traceback = opt.auto_inject_traceback; + end +end + -- Do we want any more well-known fields? -- Or could we just copy all fields from `e`? -- Sometimes you want variable details in the `text`, how to handle that? @@ -17,6 +25,12 @@ end local function new(e, context, registry) local template = (registry and registry[e]) or e or {}; + context = context or template.context or { _error_id = e }; + + if auto_inject_traceback then + context.traceback = debug.traceback("error stack", 2); + end + return setmetatable({ type = template.type or "cancel"; condition = template.condition or "undefined-condition"; @@ -57,4 +71,5 @@ return { coerce = coerce; is_err = is_err; from_stanza = from_stanza; + configure = configure; } diff --git a/util/startup.lua b/util/startup.lua index 01ca585b..40021981 100644 --- a/util/startup.lua +++ b/util/startup.lua @@ -546,6 +546,10 @@ function startup.init_gc() return true; end +function startup.init_errors() + require "util.error".configure(config.get("*", "error_library")); +end + function startup.make_host(hostname) return { type = "local", @@ -577,6 +581,7 @@ function startup.prosodyctl() startup.force_console_logging(); startup.init_logging(); startup.init_gc(); + startup.init_errors(); startup.setup_plugindir(); -- startup.setup_plugin_install_path(); startup.setup_datadir(); @@ -600,6 +605,7 @@ function startup.prosody() startup.read_config(); startup.init_logging(); startup.init_gc(); + startup.init_errors(); startup.sanity_check(); startup.sandbox_require(); startup.set_function_metatable(); |