From 8a8feae205ea636b626c75e6ace8237d7eb2da8e Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Wed, 24 Apr 2024 02:06:33 +0200 Subject: add more error logging --- .../features/garden/visitor/GardenVisitorSupercraft.kt | 18 ++++++++++++++++-- .../bazaar/BazaarCancelledBuyOrderClipboard.kt | 12 ++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt index e2343af02..ba5706f1d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacks import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.garden.visitor.VisitorOpenEvent +import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.NEUInternalName @@ -50,11 +51,24 @@ class GardenVisitorSupercraft { val visitor = event.visitor visitor.offer?.offerItem ?: return for ((internalName, amount) in visitor.shoppingList) { - if (isSupercraftEnabled) getSupercraftForSacks(internalName, amount) + if (isSupercraftEnabled) { + try { + getSupercraftForSacks(internalName, amount) + } catch (e: NoSuchElementException) { + ErrorManager.logErrorWithData( + e, + "Failed to calculate supercraft recipes for visitor", + "internalName" to internalName, + "amount" to amount, + "visitor" to visitor.visitorName, + "visitor.offer?.offerItem" to visitor.offer?.offerItem, + ) + } + } } } - fun getSupercraftForSacks(internalName: NEUInternalName, amount: Int) { + private fun getSupercraftForSacks(internalName: NEUInternalName, amount: Int) { val ingredients = NEUItems.getRecipes(internalName) // TODO describe what this line does .first { !it.ingredients.first().internalItemId.contains("PEST") } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt index aeda031d0..7a8ad18b6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.inventory.bazaar import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name @@ -47,9 +48,16 @@ class BazaarCancelledBuyOrderClipboard { val stack = event.inventoryItems[11] ?: return if (!stack.name.contains("Cancel Order")) return - stack.getLore().matchFirst(lastAmountPattern) { + val lore = stack.getLore() + lore.matchFirst(lastAmountPattern) { latestAmount = group("amount").formatInt() + return } + ErrorManager.logErrorStateWithData( + "BazaarCancelledBuyOrderClipboard error", + "lastAmountPattern can not find latestAmount", + "lore" to lore, + ) } @SubscribeEvent @@ -59,7 +67,7 @@ class BazaarCancelledBuyOrderClipboard { group("coins").formatInt().addSeparators() } ?: return - val latestAmount = latestAmount ?: error("latest amount is null") + val latestAmount = latestAmount ?: return event.blockedReason = "bazaar cancelled buy order clipboard" ChatUtils.chat("Bazaar buy order cancelled. ${latestAmount.addSeparators()} saved to clipboard. ($coins coins)") OSUtils.copyToClipboard(latestAmount.toString()) -- cgit