IMPORTANT: due to a drive failure, as of 13-Mar-2021, the Mercurial repository had to be re-mirrored, which changed every commit SHA. The old SHAs and trees are backed up in the vault branches. Please migrate to the new branches as soon as you can.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
prosody/util/error.lua

52 lines
1.1 KiB

local error_mt = { __name = "error" };
function error_mt:__tostring()
return ("error<%s:%s:%s>"):format(self.type, self.condition, self.text or "");
end
local function is_err(e)
return getmetatable(e) == error_mt;
end
local function new(e, context, registry)
local template = (registry and registry[e]) or e or {};
return setmetatable({
type = template.type or "cancel";
condition = template.condition or "undefined-condition";
text = template.text;
context = context or template.context or { _error_id = e };
}, error_mt);
end
local function coerce(ok, err, ...)
if ok or is_err(err) then
return ok, err, ...;
end
local new_err = setmetatable({
native = err;
type = "cancel";
condition = "undefined-condition";
}, error_mt);
return ok, new_err, ...;
end
local function from_stanza(stanza, context)
local error_type, condition, text = stanza:get_error();
return setmetatable({
type = error_type or "cancel";
condition = condition or "undefined-condition";
text = text;
context = context or { stanza = stanza };
}, error_mt);
end
return {
new = new;
coerce = coerce;
is_err = is_err;
from_stanza = from_stanza;
}