Comparison

util/error.lua @ 11053:04ad9555c799

util.error: Add a 'source' parameter where origin module can be mentioned
author Kim Alvefur <zash@zash.se>
date Fri, 28 Aug 2020 13:54:16 +0200
parent 11051:08539aa129ee
child 11054:ad07152d7bde
comparison
equal deleted inserted replaced
11052:1f42b08b134f 11053:04ad9555c799
31 -- Sometimes you want variable details in the `text`, how to handle that? 31 -- Sometimes you want variable details in the `text`, how to handle that?
32 -- Translations? 32 -- Translations?
33 -- Should the `type` be restricted to the stanza error types or free-form? 33 -- Should the `type` be restricted to the stanza error types or free-form?
34 -- What to set `type` to for stream errors or SASL errors? Those don't have a 'type' attr. 34 -- What to set `type` to for stream errors or SASL errors? Those don't have a 'type' attr.
35 35
36 local function new(e, context, registry) 36 local function new(e, context, registry, source)
37 local template = (registry and registry[e]) or e or {}; 37 local template = (registry and registry[e]) or e or {};
38 context = context or template.context or { _error_id = e }; 38 context = context or template.context or { _error_id = e };
39 39
40 if auto_inject_traceback then 40 if auto_inject_traceback then
41 context.traceback = debug.traceback("error stack", 2); 41 context.traceback = debug.traceback("error stack", 2);
46 condition = template.condition or "undefined-condition"; 46 condition = template.condition or "undefined-condition";
47 text = template.text; 47 text = template.text;
48 code = template.code; 48 code = template.code;
49 49
50 context = context or template.context or { _error_id = e }; 50 context = context or template.context or { _error_id = e };
51 source = source;
51 }, error_mt); 52 }, error_mt);
52 end 53 end
53 54
54 local function coerce(ok, err, ...) 55 local function coerce(ok, err, ...)
55 if ok or is_err(err) then 56 if ok or is_err(err) then