Changeset

9480:006a71a83e6a

util.serialization: Make errors fatal by default (like the previous implementation)
author Kim Alvefur <zash@zash.se>
date Thu, 11 Oct 2018 22:42:17 +0200
parents 9479:3a683b2476e2
children 9481:f34c635c5f42
files spec/util_serialization_spec.lua util/serialization.lua
diffstat 2 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/spec/util_serialization_spec.lua	Thu Oct 11 18:20:09 2018 +0100
+++ b/spec/util_serialization_spec.lua	Thu Oct 11 22:42:17 2018 +0200
@@ -7,9 +7,19 @@
 			assert.is_string(serialization.serialize(nil));
 			assert.is_string(serialization.serialize(1));
 			assert.is_string(serialization.serialize(true));
-			assert.is_string(serialization.serialize(function () end));
 		end);
 
+		it("rejects function by default", function ()
+			assert.has_error(function ()
+				serialization.serialize(function () end)
+			end);
+		end);
+
+		it("makes a string in debug mode", function ()
+			assert.is_string(serialization.serialize(function () end, "debug"));
+		end);
+
+
 		it("roundtrips", function ()
 			local function test(data)
 				local serialized = serialization.serialize(data);
--- a/util/serialization.lua	Thu Oct 11 18:20:09 2018 +0100
+++ b/util/serialization.lua	Thu Oct 11 22:42:17 2018 +0200
@@ -103,7 +103,7 @@
 		opt.equals = opt.equals or "=";
 	end
 
-	local fallback = opt.fatal and fatal_error or opt.fallback or default_fallback;
+	local fallback = opt.fallback or opt.fatal == false and default_fallback or fatal_error;
 
 	local function ser(v)
 		return (types[type(v)] or fallback)(v);