Comparison

util/error.lua @ 11054:ad07152d7bde

util.error: Add a wrapper for common parameters Lets you set up source and registry once per module
author Kim Alvefur <zash@zash.se>
date Fri, 28 Aug 2020 13:55:05 +0200
parent 11053:04ad9555c799
child 11075:d8fad2b48b05
comparison
equal deleted inserted replaced
11053:04ad9555c799 11054:ad07152d7bde
50 context = context or template.context or { _error_id = e }; 50 context = context or template.context or { _error_id = e };
51 source = source; 51 source = source;
52 }, error_mt); 52 }, error_mt);
53 end 53 end
54 54
55 local function init(source, registry)
56 return function (e, context)
57 return new(e, context, registry, source);
58 end
59 end
60
55 local function coerce(ok, err, ...) 61 local function coerce(ok, err, ...)
56 if ok or is_err(err) then 62 if ok or is_err(err) then
57 return ok, err, ...; 63 return ok, err, ...;
58 end 64 end
59 65
77 }, error_mt); 83 }, error_mt);
78 end 84 end
79 85
80 return { 86 return {
81 new = new; 87 new = new;
88 init = init;
82 coerce = coerce; 89 coerce = coerce;
83 is_err = is_err; 90 is_err = is_err;
84 from_stanza = from_stanza; 91 from_stanza = from_stanza;
85 configure = configure; 92 configure = configure;
86 } 93 }