From 5140390111933c9f612cc7858f14255a97a53ccd Mon Sep 17 00:00:00 2001 From: Aditya Gupta Date: Mon, 13 Jul 2026 15:37:21 +0530 Subject: [PATCH 1/2] add explicit error handling for non table argument #1 in table.insert and table.remove --- src/ModUtil.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ModUtil.lua b/src/ModUtil.lua index 02c27ed..5289a69 100644 --- a/src/ModUtil.lua +++ b/src/ModUtil.lua @@ -176,6 +176,9 @@ local rawinsert = table.rawinsert ---@type fun( list, pos, value?: any ) ---@diagnostic disable-next-line: duplicate-set-field function table.insert( list, pos, value ) + if type(list) ~= "table" then + error( "bad argument #1 to '" .. getname( ) .. "' (expected type 'table', received type '" .. type(list) .."')", 2 ) + end local last = #list if value == nil then value = pos @@ -199,6 +202,9 @@ table.rawremove = table.remove ---@type fun( list, pos ): any ---@diagnostic disable-next-line: duplicate-set-field function table.remove( list, pos ) + if type(list) ~= "table" then + error( "bad argument #1 to '" .. getname( ) .. "' (expected type 'table', received type '" .. type(list) .."')", 2 ) + end local last = #list if pos == nil then pos = last From 831b6ac314c85b4159011b9dccce8f52efbdf0fd Mon Sep 17 00:00:00 2001 From: Aditya Gupta Date: Mon, 13 Jul 2026 16:21:01 +0530 Subject: [PATCH 2/2] update error msg to be same as vanilla --- src/ModUtil.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ModUtil.lua b/src/ModUtil.lua index 5289a69..76ee5bf 100644 --- a/src/ModUtil.lua +++ b/src/ModUtil.lua @@ -177,7 +177,7 @@ local rawinsert = table.rawinsert ---@diagnostic disable-next-line: duplicate-set-field function table.insert( list, pos, value ) if type(list) ~= "table" then - error( "bad argument #1 to '" .. getname( ) .. "' (expected type 'table', received type '" .. type(list) .."')", 2 ) + error( "bad argument #1 to '" .. getname( ) .. "' (table expected, got " .. type(list) ..")", 2 ) end local last = #list if value == nil then @@ -203,7 +203,7 @@ table.rawremove = table.remove ---@diagnostic disable-next-line: duplicate-set-field function table.remove( list, pos ) if type(list) ~= "table" then - error( "bad argument #1 to '" .. getname( ) .. "' (expected type 'table', received type '" .. type(list) .."')", 2 ) + error( "bad argument #1 to '" .. getname( ) .. "' (table expected, got " .. type(list) ..")", 2 ) end local last = #list if pos == nil then