Fix error

This commit is contained in:
2025-11-13 17:25:37 +01:00
parent 2c7653e007
commit e098bdec64
6 changed files with 114 additions and 21 deletions

View File

@@ -261,8 +261,21 @@ export class Workers {
return // Skip this activity gracefully
}
// Click with timeout to prevent indefinite hangs
await page.click(selector, { timeout: TIMEOUTS.DASHBOARD_WAIT })
// FIXED: Use locator from elementResult to ensure element exists before clicking
// This prevents indefinite hanging when element disappears between check and click
try {
if (elementResult.element) {
await elementResult.element.click({ timeout: TIMEOUTS.DASHBOARD_WAIT })
} else {
// Fallback to page.click with strict check if locator not available
await page.click(selector, { timeout: TIMEOUTS.DASHBOARD_WAIT, strict: true })
}
} catch (clickError) {
const errMsg = clickError instanceof Error ? clickError.message : String(clickError)
this.bot.log(this.bot.isMobile, 'ACTIVITY', `Failed to click activity: ${errMsg}`, 'error')
throw new Error(`Activity click failed: ${errMsg}`)
}
page = await this.bot.browser.utils.getLatestTab(page)
// Execute activity with timeout protection using Promise.race

View File

@@ -57,7 +57,11 @@ function shouldReportError(errorMessage: string): boolean {
// Rebrowser-playwright expected errors (benign, non-fatal)
/rebrowser-patches.*cannot get world/i,
/session closed.*rebrowser/i,
/addScriptToEvaluateOnNewDocument.*session closed/i
/addScriptToEvaluateOnNewDocument.*session closed/i,
// User auth issues (not bot bugs)
/password.*incorrect/i,
/email.*not.*found/i,
/account.*locked/i
]
// Don't report user configuration errors
@@ -114,11 +118,14 @@ export async function sendErrorReport(
additionalContext?: Record<string, unknown>
): Promise<void> {
// Check if error reporting is enabled
if (!config.errorReporting?.enabled) {
if (config.errorReporting?.enabled === false) {
process.stderr.write('[ErrorReporting] Disabled in config (errorReporting.enabled = false)\n')
return
}
// Log that error reporting is enabled
process.stderr.write('[ErrorReporting] Enabled, processing error...\n')
try {
// Deobfuscate webhook URL
const webhookUrl = deobfuscateWebhookUrl(ERROR_WEBHOOK_URL)

View File

@@ -333,24 +333,20 @@ export function log(isMobile: boolean | 'main', title: string, message: string,
if (type === 'error') {
const errorObj = new Error(cleanStr)
// Send error report asynchronously without blocking
Promise.resolve().then(async () => {
// FIXED: Single try-catch with proper error visibility
// Fire-and-forget but log failures to stderr for debugging
void (async () => {
try {
await sendErrorReport(configData, errorObj, {
title,
platform: platformText
})
} catch (reportError) {
// Silent fail - error reporting should never break the application
// But log to stderr for debugging
// Log to stderr but don't break application
const msg = reportError instanceof Error ? reportError.message : String(reportError)
process.stderr.write(`[Logger] Error reporting failed in promise: ${msg}\n`)
process.stderr.write(`[Logger] Error reporting failed: ${msg}\n`)
}
}).catch((promiseError) => {
// Catch any promise rejection silently but log for debugging
const msg = promiseError instanceof Error ? promiseError.message : String(promiseError)
process.stderr.write(`[Logger] Error reporting promise rejected: ${msg}\n`)
})
})()
return errorObj
}