From 87312d30ec259a2f524b94f7bee851a47a72e863 Mon Sep 17 00:00:00 2001 From: mindesbunister Date: Fri, 25 Jul 2025 10:18:19 +0200 Subject: [PATCH] Enhanced automation error handling and monitoring - Add comprehensive error tracking with consecutive error counts - Implement automatic shutdown after 3 consecutive failures - Reset error counter on successful cycles - Add detailed error logging with stack traces - Improve automation reliability and debugging capability This should prevent silent automation failures and provide better visibility into why automation stops --- lib/simple-automation.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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`); } }