util.error: Add a wrapper for common parameters
authorKim Alvefur <zash@zash.se>
Fri, 28 Aug 2020 13:55:05 +0200
changeset 11058 ad07152d7bde
parent 11057 04ad9555c799
child 11059 5fb95410f89c
util.error: Add a wrapper for common parameters Lets you set up source and registry once per module
util/error.lua
--- a/util/error.lua	Fri Aug 28 13:54:16 2020 +0200
+++ b/util/error.lua	Fri Aug 28 13:55:05 2020 +0200
@@ -52,6 +52,12 @@
 	}, error_mt);
 end
 
+local function init(source, registry)
+	return function (e, context)
+		return new(e, context, registry, source);
+	end
+end
+
 local function coerce(ok, err, ...)
 	if ok or is_err(err) then
 		return ok, err, ...;
@@ -79,6 +85,7 @@
 
 return {
 	new = new;
+	init = init;
 	coerce = coerce;
 	is_err = is_err;
 	from_stanza = from_stanza;