From b85dc4694a6e2f59039c27b7c1a94b9e0be0ed27 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Mon, 10 Jul 2017 10:51:07 +0200 Subject: [PATCH] Added specific error message on 'strict table' when table is empty --- errors.lua | 1 + test/test_errors.lua | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/errors.lua b/errors.lua index c2b8ae2..84a9798 100644 --- a/errors.lua +++ b/errors.lua @@ -146,6 +146,7 @@ return function (module_name) __index = function (t, k) local keys = {} for k in pairs(t) do keys[#keys+1] = k end + if #keys then external_error(err_hdl, '', 'Attempting to index unknown key %s in an empty table.', k) end correct_error(err_hdl, '', 'Attempting to index unknown key %s, maybe you meant %s?', k, keys) end }) diff --git a/test/test_errors.lua b/test/test_errors.lua index 41757a9..69a508a 100644 --- a/test/test_errors.lua +++ b/test/test_errors.lua @@ -107,6 +107,11 @@ SUITE:addTest('Strict tables throw errors on unknown indices', function() bad_call(function() return t.hello end) end) +SUITE:addTest('Strict tables throw specific error on empty table', function() + local t = error.strict_table {} + bad_call(function() return t.hello end) +end) + --------------------------------------------------------------------------------