Changeset

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
parents 11053:04ad9555c799
children 11055:5fb95410f89c
files util/error.lua
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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;