mirror of
https://github.com/LightZirconite/Microsoft-Rewards-Bot.git
synced 2026-01-09 17:06:15 +00:00
Fix error
This commit is contained in:
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "microsoft-rewards-bot",
|
||||
"version": "2.56.9",
|
||||
"version": "2.56.10",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "microsoft-rewards-bot",
|
||||
"version": "2.56.9",
|
||||
"version": "2.56.10",
|
||||
"hasInstallScript": true,
|
||||
"license": "CC-BY-NC-SA-4.0",
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "microsoft-rewards-bot",
|
||||
"version": "2.56.9",
|
||||
"version": "2.56.10",
|
||||
"description": "Automate Microsoft Rewards points collection",
|
||||
"private": true,
|
||||
"main": "index.js",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import assert from 'node:assert'
|
||||
import { describe, it } from 'node:test'
|
||||
import { deobfuscateWebhookUrl, obfuscateWebhookUrl } from '../src/util/ErrorReportingWebhook'
|
||||
import { Config } from '../src/interface/Config'
|
||||
import { deobfuscateWebhookUrl, obfuscateWebhookUrl, sendErrorReport } from '../src/util/notifications/ErrorReportingWebhook'
|
||||
|
||||
describe('ErrorReportingWebhook', () => {
|
||||
describe('URL obfuscation', () => {
|
||||
@@ -8,7 +9,7 @@ describe('ErrorReportingWebhook', () => {
|
||||
const originalUrl = 'https://discord.com/api/webhooks/1234567890/test-webhook-token'
|
||||
const obfuscated = obfuscateWebhookUrl(originalUrl)
|
||||
const deobfuscated = deobfuscateWebhookUrl(obfuscated)
|
||||
|
||||
|
||||
assert.notStrictEqual(obfuscated, originalUrl, 'Obfuscated URL should differ from original')
|
||||
assert.strictEqual(deobfuscated, originalUrl, 'Deobfuscated URL should match original')
|
||||
})
|
||||
@@ -27,12 +28,88 @@ describe('ErrorReportingWebhook', () => {
|
||||
it('should verify project webhook URL', () => {
|
||||
const projectWebhook = 'https://discord.com/api/webhooks/1437111962394689629/tlvGKZaH9-rJir4tnZKSZpRHS3YbeN4vZnuCv50k5MpADYRPnHnZ6MybAlgF5QFo6KH_'
|
||||
const expectedObfuscated = 'aHR0cHM6Ly9kaXNjb3JkLmNvbS9hcGkvd2ViaG9va3MvMTQzNzExMTk2MjM5NDY4OTYyOS90bHZHS1phSDktckppcjR0blpLU1pwUkhTM1liZU40dlpudUN2NTBrNU1wQURZUlBuSG5aNk15YkFsZ0Y1UUZvNktIXw=='
|
||||
|
||||
|
||||
const obfuscated = obfuscateWebhookUrl(projectWebhook)
|
||||
assert.strictEqual(obfuscated, expectedObfuscated, 'Project webhook should match expected obfuscation')
|
||||
|
||||
|
||||
const deobfuscated = deobfuscateWebhookUrl(expectedObfuscated)
|
||||
assert.strictEqual(deobfuscated, projectWebhook, 'Deobfuscated should match original project webhook')
|
||||
})
|
||||
})
|
||||
|
||||
describe('sendErrorReport', () => {
|
||||
it('should respect enabled flag when true (dry run with invalid config)', async () => {
|
||||
// This test verifies the flow works when enabled = true
|
||||
// Uses invalid webhook URL to prevent actual network call
|
||||
const mockConfig: Partial<Config> = {
|
||||
errorReporting: { enabled: true }
|
||||
}
|
||||
|
||||
// Should not throw even with invalid config (graceful degradation)
|
||||
await assert.doesNotReject(
|
||||
async () => {
|
||||
await sendErrorReport(mockConfig as Config, new Error('Test error'))
|
||||
},
|
||||
'sendErrorReport should not throw when enabled'
|
||||
)
|
||||
})
|
||||
|
||||
it('should skip sending when explicitly disabled', async () => {
|
||||
const mockConfig: Partial<Config> = {
|
||||
errorReporting: { enabled: false }
|
||||
}
|
||||
|
||||
// Should return immediately without attempting network call
|
||||
await assert.doesNotReject(
|
||||
async () => {
|
||||
await sendErrorReport(mockConfig as Config, new Error('Test error'))
|
||||
},
|
||||
'sendErrorReport should not throw when disabled'
|
||||
)
|
||||
})
|
||||
|
||||
it('should filter out expected errors (configuration issues)', async () => {
|
||||
const mockConfig: Partial<Config> = {
|
||||
errorReporting: { enabled: true }
|
||||
}
|
||||
|
||||
// These errors should be filtered by shouldReportError()
|
||||
const expectedErrors = [
|
||||
'accounts.jsonc not found',
|
||||
'Invalid credentials',
|
||||
'Login failed',
|
||||
'Account suspended',
|
||||
'EADDRINUSE: Port already in use'
|
||||
]
|
||||
|
||||
for (const errorMsg of expectedErrors) {
|
||||
await assert.doesNotReject(
|
||||
async () => {
|
||||
await sendErrorReport(mockConfig as Config, new Error(errorMsg))
|
||||
},
|
||||
`Should handle expected error: ${errorMsg}`
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('should sanitize sensitive data from error messages', async () => {
|
||||
const mockConfig: Partial<Config> = {
|
||||
errorReporting: { enabled: true }
|
||||
}
|
||||
|
||||
// Error containing sensitive data
|
||||
const sensitiveError = new Error('Login failed for user@example.com at C:\\Users\\test\\path with token abc123def456ghi789012345')
|
||||
|
||||
// Should not throw and should sanitize internally
|
||||
await assert.doesNotReject(
|
||||
async () => {
|
||||
await sendErrorReport(mockConfig as Config, sensitiveError, {
|
||||
userPath: '/home/user/secrets',
|
||||
ipAddress: '192.168.1.100'
|
||||
})
|
||||
},
|
||||
'Should handle errors with sensitive data'
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user