mirror of
https://github.com/LightZirconite/Microsoft-Rewards-Bot.git
synced 2026-01-11 09:46:16 +00:00
feat: Refactor compromised mode handling and improve error logging across flows
This commit is contained in:
@@ -92,13 +92,14 @@ export class Activities {
|
||||
await this.doUrlReward(page)
|
||||
break
|
||||
case 'unsupported':
|
||||
// FIXED: Added explicit default case
|
||||
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Skipped activity "${activity.title}" | Reason: Unsupported type: "${String((activity as { promotionType?: string }).promotionType)}"!`, 'warn')
|
||||
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Skipped activity "${activity.title}" | Reason: Unsupported type: "${(activity as { promotionType?: string }).promotionType || 'unknown'}"`, 'warn')
|
||||
break
|
||||
default:
|
||||
// Exhaustiveness check - should never reach here due to ActivityKind type
|
||||
default: {
|
||||
// Exhaustiveness check - TypeScript ensures all ActivityKind types are handled
|
||||
const _exhaustive: never = kind
|
||||
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Unexpected activity kind for "${activity.title}"`, 'error')
|
||||
break
|
||||
return _exhaustive
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Dispatcher error for "${activity.title}": ${e instanceof Error ? e.message : e}`, 'error')
|
||||
|
||||
@@ -237,26 +237,21 @@ export class Workers {
|
||||
await page.click(selector, { timeout: 10000 })
|
||||
page = await this.bot.browser.utils.getLatestTab(page)
|
||||
|
||||
// FIXED: Use AbortController for proper cancellation instead of race condition
|
||||
// Execute activity with timeout protection using Promise.race
|
||||
const timeoutMs = this.bot.utils.stringToMs(this.bot.config?.globalTimeout ?? '30s') * 2
|
||||
const controller = new AbortController()
|
||||
const timeoutHandle = setTimeout(() => {
|
||||
controller.abort()
|
||||
}, timeoutMs)
|
||||
|
||||
const runWithTimeout = async (p: Promise<void>) => {
|
||||
try {
|
||||
await p
|
||||
clearTimeout(timeoutHandle)
|
||||
} catch (error) {
|
||||
clearTimeout(timeoutHandle)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
await retry.run(async () => {
|
||||
const activityPromise = this.bot.activities.run(page, activity)
|
||||
const timeoutPromise = new Promise<never>((_, reject) => {
|
||||
const timer = setTimeout(() => {
|
||||
reject(new Error(`Activity execution timeout after ${timeoutMs}ms`))
|
||||
}, timeoutMs)
|
||||
// Clean up timer if activity completes first
|
||||
activityPromise.finally(() => clearTimeout(timer))
|
||||
})
|
||||
|
||||
try {
|
||||
await runWithTimeout(this.bot.activities.run(page, activity))
|
||||
await Promise.race([activityPromise, timeoutPromise])
|
||||
throttle.record(true)
|
||||
} catch (e) {
|
||||
throttle.record(false)
|
||||
|
||||
Reference in New Issue
Block a user