From 6072cecc4fb1724ae4160b191a69b072dba780c6 Mon Sep 17 00:00:00 2001 From: gc <30398469+gc@users.noreply.github.com> Date: Sat, 13 Jul 2024 20:03:34 +1000 Subject: [PATCH] Cleanup some logs/error handling --- src/lib/Task.ts | 10 +++++----- src/lib/grandExchange.ts | 10 +++++----- src/lib/util/globalInteractions.ts | 5 ----- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/lib/Task.ts b/src/lib/Task.ts index fce856a374..5ea4db1a2f 100644 --- a/src/lib/Task.ts +++ b/src/lib/Task.ts @@ -236,15 +236,16 @@ const ActivityTaskOptionsSchema = z.object({ async function completeActivity(_activity: Activity) { const activity = convertStoredActivityToFlatActivity(_activity); - debugLog(`Attemping to complete activity ID[${activity.id}]`); if (_activity.completed) { - throw new Error('Tried to complete an already completed task.'); + logError(new Error('Tried to complete an already completed task.')); + return; } const task = tasks.find(i => i.type === activity.type)!; if (!task) { - throw new Error('Missing task'); + logError(new Error('Missing task')); + return; } modifyBusyCounter(activity.userID, 1); @@ -253,7 +254,7 @@ async function completeActivity(_activity: Activity) { const schema = ActivityTaskOptionsSchema.and(task.dataSchema); const { success } = schema.safeParse(activity); if (!success) { - console.error(`Invalid activity data for ${activity.type} task: ${JSON.stringify(activity)}`); + logError(new Error(`Invalid activity data for ${activity.type} task: ${JSON.stringify(activity)}`)); } } await task.run(activity); @@ -262,7 +263,6 @@ async function completeActivity(_activity: Activity) { } finally { modifyBusyCounter(activity.userID, -1); minionActivityCacheDelete(activity.userID); - debugLog(`Finished completing activity ID[${activity.id}]`); } } diff --git a/src/lib/grandExchange.ts b/src/lib/grandExchange.ts index c2581bdbb6..26befe12d4 100644 --- a/src/lib/grandExchange.ts +++ b/src/lib/grandExchange.ts @@ -537,9 +537,9 @@ ${type} ${toKMB(quantity)} ${item.name} for ${toKMB(price)} each, for a total of buyerListing.asking_price_per_item }] SellerPrice[${ sellerListing.asking_price_per_item - }] TotalPriceBeforeTax[${totalPriceBeforeTax}] QuantityToBuy[${quantityToBuy}] TotalTaxPaid[${totalTaxPaid}] BuyerRefund[${buyerRefund}] BuyerLoot[${buyerLoot}] SellerLoot[${sellerLoot}] CurrentGEBank[${geBank}] BankToRemoveFromGeBank[${bankToRemoveFromGeBank}] ExpectedAfterBank[${geBank - .clone() - .remove(bankToRemoveFromGeBank)}]`; + }] TotalPriceBeforeTax[${totalPriceBeforeTax}] QuantityToBuy[${quantityToBuy}] TotalTaxPaid[${totalTaxPaid}] BuyerRefund[${buyerRefund}] BuyerLoot[${buyerLoot}] SellerLoot[${sellerLoot}] CurrentGEBank[${geBank}] BankToRemoveFromGeBank[${bankToRemoveFromGeBank.bank}] ExpectedAfterBank[${ + geBank.clone().remove(bankToRemoveFromGeBank).bank + }]`; assert( bankToRemoveFromGeBank.amount('Coins') === Number(buyerListing.asking_price_per_item) * quantityToBuy, @@ -557,7 +557,7 @@ ${type} ${toKMB(quantity)} ${item.name} for ${toKMB(price)} each, for a total of } debugLog( - `Completing a transaction, removing ${bankToRemoveFromGeBank} from the GE bank, ${totalTaxPaid} in taxed gp. The current GE bank is ${geBank.toString()}. ${debug}`, + `Completing a transaction, removing ${bankToRemoveFromGeBank.bank} from the GE bank, ${totalTaxPaid} in taxed gp. The current GE bank is ${geBank.bank}. ${debug}`, { totalPriceAfterTax, totalTaxPaid, @@ -617,7 +617,7 @@ ${type} ${toKMB(quantity)} ${item.name} for ${toKMB(price)} each, for a total of ...makeTransactFromTableBankQueries({ bankToRemove: bankToRemoveFromGeBank }) ]); - debugLog(`Transaction completed, the new G.E bank is ${await this.fetchOwnedBank()}.`); + debugLog(`Transaction completed, the new G.E bank is ${(await this.fetchOwnedBank()).bank}.`); const buyerUser = await mUserFetch(buyerListing.user_id); const sellerUser = await mUserFetch(sellerListing.user_id); diff --git a/src/lib/util/globalInteractions.ts b/src/lib/util/globalInteractions.ts index 9ff0c472b6..1bccb15c59 100644 --- a/src/lib/util/globalInteractions.ts +++ b/src/lib/util/globalInteractions.ts @@ -329,11 +329,6 @@ export async function interactionHook(interaction: Interaction) { }); } - debugLog(`Interaction hook for button [${interaction.customId}]`, { - user_id: interaction.user.id, - channel_id: interaction.channelId, - guild_id: interaction.guildId - }); const id = interaction.customId; const userID = interaction.user.id;