core/run_command: be more robust in case of programming errors

This commit is contained in:
Starbeamrainbowlabs 2023-12-13 23:04:09 +00:00
parent 873ff4bef8
commit b92cc434db
Signed by: sbrl
GPG key ID: C1C6C0BB001E1725

View file

@ -37,9 +37,12 @@ local function run_command(cmdname, options, player_name, paramtext)
end
local parse_result = { options.parse(paramtext) }
if #parse_result >= 2 and parse_result[1] == false and type(parse_result[2]) ~= "string" then
minetest.log("warning", "[WorldEditAdditions:core] This is a bug. Parsing function for cmd "..cmdname.." failed but provided value of type "..type(parse_result[2]).." as an error message instead of the expected value of type string.All output from the parsing function: "..wea_c.inspect(parse_result))
end
local success = table.remove(parse_result, 1)
if not success then
worldedit.player_notify(player_name, parse_result[1] or "Invalid usage (no further error message was provided by the command. This is probably a bug.)")
worldedit.player_notify(player_name, tostring(parse_result[1]) or "Invalid usage (no further error message was provided by the command. This is probably a bug.)")
return false
end