# HG changeset patch # User Kim Alvefur # Date 1539290537 -7200 # Node ID 006a71a83e6afc40b10233e953a82c7e20768846 # Parent 3a683b2476e2b7a4aa4e3f1da7c2d44ffa10ed0a util.serialization: Make errors fatal by default (like the previous implementation) diff -r 3a683b2476e2 -r 006a71a83e6a spec/util_serialization_spec.lua --- 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); diff -r 3a683b2476e2 -r 006a71a83e6a util/serialization.lua --- 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);