From 9d320bf9f941151573fd9d1db7d535853cfde2c1 Mon Sep 17 00:00:00 2001 From: Kelin Date: Thu, 29 Jan 2026 19:59:13 -0500 Subject: [PATCH] Fix menu.sh service counting robustness - Add error handling to prevent script crashes during service enumeration - Make service counting more robust against parsing failures - Ensure menu displays properly even with docker-compose parsing issues - Menu now shows complete interface with all 8 main options --- scripts/enhanced-setup/menu.sh | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/scripts/enhanced-setup/menu.sh b/scripts/enhanced-setup/menu.sh index b76b5a9..ef124a6 100755 --- a/scripts/enhanced-setup/menu.sh +++ b/scripts/enhanced-setup/menu.sh @@ -130,11 +130,21 @@ show_system_status() { fi # Service count - local service_count - service_count=$(find_all_services | wc -l) - if (( service_count > 0 )); then - local running_count - running_count=$(find_all_services | while read -r service; do is_service_running "$service" && echo "1"; done | wc -l) + local service_count=0 + local running_count=0 + + # Safely count services with error handling + if service_list=$(find_all_services 2>/dev/null); then + service_count=$(echo "$service_list" | wc -l 2>/dev/null || echo "0") + # Remove whitespace and ensure it's a number + service_count=$(echo "$service_count" | tr -d '[:space:]' | sed 's/[^0-9]*//g') + if [[ "$service_count" =~ ^[0-9]+$ ]] && (( service_count > 0 )); then + running_count=$(echo "$service_list" | while read -r service; do is_service_running "$service" 2>/dev/null && echo "1"; done | wc -l 2>/dev/null || echo "0") + running_count=$(echo "$running_count" | tr -d '[:space:]' | sed 's/[^0-9]*//g') + fi + fi + + if [[ "$service_count" =~ ^[0-9]+$ ]] && (( service_count > 0 )); then echo "✅ Services: $running_count/$service_count running" else echo "ℹ️ Services: None deployed yet"