From 686c1e58084c5ee31e43533a1cd5fb3d9a7920a3 Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Thu, 28 Nov 2024 22:50:58 +0100 Subject: [PATCH] Hook debugger on error condition --- storage/itemstack.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/storage/itemstack.lua b/storage/itemstack.lua index 778a168..27dcbef 100644 --- a/storage/itemstack.lua +++ b/storage/itemstack.lua @@ -7,6 +7,13 @@ local Debugger = require("debugger") local ItemStack = Sentinel:tag({}, Sentinel.ITEMSTACK) ItemStack.__index = ItemStack +local function hookDebugger() + local errorCond = Debugger.debugREPL(function(retval) + Logger:error("->", retval) + end) + Logger:error("x>", errorCond) +end + function ItemStack:fromDetail(inv, detail, slot) local obj = { slot = slot, @@ -193,6 +200,10 @@ function ItemStack:_modify(countDelta, stack) end function ItemStack:transferTo(target, count) + if target:getMaxCount() == nil then + Logger:error("Max count is nil?", target, "\n", self, "\n", count) + hookDebugger() + end local cap = math.min(count or self:getCount(), target:getMaxCount() - target:getCount(), self:getCount()) -- If we can't transfer any data, then @@ -222,10 +233,7 @@ function ItemStack:transferTo(target, count) target:getInventory().getItemLimit(target:getSlot()), "\n", result ) - local errorCond = Debugger.debugREPL(function(retval) - Logger:error("->", retval) - end) - Logger:error("x>", errorCond) + hookDebugger() end target:_modify(result[2], self)