Diff

util/error.lua @ 11080:ba77c142c9b1

util.error: Simplify error creation flow
author Matthew Wild <mwild1@gmail.com>
date Fri, 25 Sep 2020 16:39:22 +0100
parent 11079:1e5a0e0469de
child 11081:0b68697450c5
line wrap: on
line diff
--- a/util/error.lua	Fri Sep 25 12:38:58 2020 +0100
+++ b/util/error.lua	Fri Sep 25 16:39:22 2020 +0100
@@ -35,7 +35,19 @@
 -- What to set `type` to for stream errors or SASL errors? Those don't have a 'type' attr.
 
 local function new(e, context, registry, source)
-	local template = (registry and registry[e]) or e or {};
+	local template = registry and registry[e];
+	if not template then
+		if type(e) == "table" then
+			template = {
+				code = e.code;
+				type = e.type;
+				condition = e.condition;
+				text = e.text;
+			};
+		else
+			template = {};
+		end
+	end
 	context = context or {};
 
 	if auto_inject_traceback then