From 9d94601f83fe07190c52a5bcd13d666b6860b48a Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Sun, 27 Aug 2017 11:47:05 +0200 Subject: [PATCH] Improved error checking messages for `strings_with_highest_similarity`. --- string_distance.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/string_distance.lua b/string_distance.lua index 3091744..f9a90ea 100644 --- a/string_distance.lua +++ b/string_distance.lua @@ -175,9 +175,11 @@ local function strings_with_highest_similarity (str, list_of_other_str) -- the output list is the most similar. -- Error checking - assert(type(str) == 'string') - assert(type(list_of_other_str) == 'table') - for i = 1, #list_of_other_str do assert(type(list_of_other_str[i]) == 'string') end + if type(str) ~= 'string' then error(('[errors/internal]: Bad argument #1, expected string, got %s (%s)'):format(str, type(str))) end + if type(list_of_other_str) ~= 'table' then error(('[errors/internal]: Bad argument #2, expected table, got %s (%s)'):format(list_of_other_str, type(list_of_other_str))) end + for i = 1, #list_of_other_str do + if type(list_of_other_str[i]) ~= 'string' then error(('[errors/internal]: Bad argument #2, expected sequence of strings, but got %s (%s) on index %i'):format(list_of_other_str[i], type(list_of_other_str[i])), i) end + end -- Do work local possible = {}