1 local error_mt
= { __name
= "error" };
3 function error_mt
:__tostring()
4 return ("error<%s:%s:%s>"):format(self
.type, self
.condition
, self
.text
or "");
7 local function is_err(e
)
8 return getmetatable(e
) == error_mt
;
11 local function new(e
, context
, registry
)
12 local template
= (registry
and registry
[e
]) or e
or {};
14 type = template
.type or "cancel";
15 condition
= template
.condition
or "undefined-condition";
18 context
= context
or template
.context
or { _error_id
= e
};
22 local function coerce(ok
, err
, ...)
23 if ok
or is_err(err
) then
27 local new_err
= setmetatable({
31 condition
= "undefined-condition";
33 return ok
, new_err
, ...;
36 local function from_stanza(stanza
, context
)
37 local error_type
, condition
, text
= stanza
:get_error();
39 type = error_type
or "cancel";
40 condition
= condition
or "undefined-condition";
43 context
= context
or { stanza
= stanza
};
51 from_stanza
= from_stanza
;