Skip to content

Commit

Permalink
Cleanup some logs/error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Jul 13, 2024
1 parent e405454 commit 6072cec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/lib/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -262,7 +263,6 @@ async function completeActivity(_activity: Activity) {
} finally {
modifyBusyCounter(activity.userID, -1);
minionActivityCacheDelete(activity.userID);
debugLog(`Finished completing activity ID[${activity.id}]`);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/lib/grandExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions src/lib/util/globalInteractions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 6072cec

Please sign in to comment.