Attach debugger on nil return value

This commit is contained in:
Gabriel Tofvesson 2024-11-28 22:42:39 +01:00
parent 407082dd2c
commit 0ff986a4f2

View File

@ -2,6 +2,7 @@ local Inventory = require("storage.inventory")
local Sentinel = require("storage.sentinel")
local Logging = require("logging")
local Logger = Logging.getGlobalLogger()
local Debugger = require("debugger")
local ItemStack = Sentinel:tag({}, Sentinel.ITEMSTACK)
ItemStack.__index = ItemStack
@ -199,7 +200,12 @@ function ItemStack:transferTo(target, count)
return count == 0, 0
end
local result = { pcall(self:getInventory().pushItems, peripheral.getName(target:getInventory()), self:getSlot(), cap, target:getSlot()) }
local errC = 0
local result
repeat
result = { pcall(self:getInventory().pushItems, peripheral.getName(target:getInventory()), self:getSlot(), cap, target:getSlot()) }
errC = errC + 1
until (not result[1]) or (result[2] ~= nil) or (errC > 8)
if not result[1] then
return false, result[2]
@ -207,13 +213,19 @@ function ItemStack:transferTo(target, count)
if result[2] == nil then
Logger:error(
"Error transferring item", self:getInventory().pushItems, Logger.plain("\n"),
peripheral.getName(target:getInventory()), Logger.plain("\n"),
cap, Logger.plain("\n"),
self, Logger.plain("\n"),
target, Logger.plain("\n"),
"Error transferring item", self:getInventory().pushItems, "\n",
peripheral.getName(target:getInventory()), "\n",
errC, "\n",
cap, "\n",
self, "\n",
target, "\n",
target:getInventory().getItemLimit(target:getSlot()), "\n",
result
)
local errorCond = Debugger.debugREPL(function(retval)
Logger:error("->", retval)
end)
Logger:error("x>", errorCond)
end
target:_modify(result[2], self)