# HG changeset patch # User Matthew Wild # Date 1598615500 -3600 # Node ID 08539aa129eec4b668c4f5a226961cdb8ae64a46 # Parent 51be24b16e8aebdb44061e67bb82bbaa23f443cc util.error: Add configuration for including traceback in tostring() diff -r 51be24b16e8a -r 08539aa129ee util/error.lua --- a/util/error.lua Fri Aug 28 12:40:59 2020 +0100 +++ b/util/error.lua Fri Aug 28 12:51:40 2020 +0100 @@ -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 @@ 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