diff --git a/lib/simple-automation.js b/lib/simple-automation.js index d9bc825..117520b 100644 --- a/lib/simple-automation.js +++ b/lib/simple-automation.js @@ -134,10 +134,32 @@ class SimpleAutomation { if (this.config) { // Perform actual analysis using enhanced screenshot API await this.performAnalysis(); + + // Reset error counter on successful cycle + this.stats.consecutiveErrors = 0; } } catch (error) { - console.error('Error in automation cycle:', error); + console.error('❌ CRITICAL ERROR in automation cycle:', error); + console.error('❌ Stack trace:', error.stack); + + // Increment error counter + this.stats.consecutiveErrors = (this.stats.consecutiveErrors || 0) + 1; + + // If too many consecutive errors, stop automation + if (this.stats.consecutiveErrors >= 3) { + console.error('🚨 TOO MANY ERRORS: Stopping automation after', this.stats.consecutiveErrors, 'consecutive failures'); + this.isRunning = false; + this.stats.status = 'Stopped due to errors'; + + if (this.intervalId) { + clearInterval(this.intervalId); + this.intervalId = null; + } + return; + } + + console.log(`⚠️ Error ${this.stats.consecutiveErrors}/3 - Will retry next cycle`); } }