add logging and crash-proofing for issue 17

A user has reported a crash that appears to involve a builder node (group 4) that lacks a "main" inventory somehow. This code prevents a crash in this circumstance and logs the node_image to hopefully identify the culprit.
This commit is contained in:
FaceDeer 2017-12-31 18:21:44 -07:00
parent 1de57191b0
commit fdde32283a

@ -18,6 +18,9 @@ local get_node_image = function(pos, node)
-- Record what kind of thing we've got in a builder node so its facing can be rotated properly
if minetest.get_item_group(node.name, "digtron") == 4 then
-- https://github.com/minetest-mods/digtron/issues/17 had a user encounter a crash here,
-- adding logging to hopefully catch it if it happens again.
if node_image.meta.inventory.main ~= nil then
local build_item = node_image.meta.inventory.main[1]
if build_item ~= "" then
local build_item_def = minetest.registered_nodes[ItemStack(build_item):get_name()]
@ -25,6 +28,9 @@ local get_node_image = function(pos, node)
node_image.build_item_paramtype2 = build_item_def.paramtype2
end
end
else
minetest.log("error", string.format("Digtron node in group 4 lacks a 'main' inventory. Please update the issue at https://github.com/minetest-mods/digtron/issues/17. Node image: %s", dump(node_image)))
end
end
return node_image
end