FIX: Improve startup flow error handling and correctness

CRITICAL: Library sourcing error handling
- launcher.sh lines 21-25: Added error checks for all source commands
- Each library now reports if it fails to load
- Script exits with message instead of silent failure

MEDIUM: init_directories error checking
- launcher.sh lines 630-631: Added error handling for mkdir -p
- Script now reports if directory creation fails
- Better user feedback on initialization errors

HIGH: Stderr redirect cleanup
- run.sh line 14: Removed misplaced 2>/dev/null after closing bracket
- launcher.sh lines 678, 694: Reordered redirects for clarity
  (read ... </dev/tty 2>/dev/null instead of 2>/dev/null </dev/tty)

REASON: Improves startup robustness by catching initialization failures
early and providing helpful error messages instead of silent failures.
This commit is contained in:
Developer
2026-03-19 22:37:46 -04:00
parent 9ab5298f85
commit ac6c0b5c12
2 changed files with 16 additions and 12 deletions
+15 -11
View File
@@ -18,11 +18,11 @@ LIB_DIR="$BASE_DIR/lib"
CONFIG_DIR="$BASE_DIR/config" CONFIG_DIR="$BASE_DIR/config"
# Load core libraries # Load core libraries
source "$LIB_DIR/common-functions.sh" source "$LIB_DIR/common-functions.sh" || { echo "ERROR: Failed to load common-functions.sh"; exit 1; }
source "$LIB_DIR/system-detect.sh" source "$LIB_DIR/system-detect.sh" || { echo "ERROR: Failed to load system-detect.sh"; exit 1; }
source "$LIB_DIR/domain-discovery.sh" source "$LIB_DIR/domain-discovery.sh" || { echo "ERROR: Failed to load domain-discovery.sh"; exit 1; }
source "$LIB_DIR/user-manager.sh" source "$LIB_DIR/user-manager.sh" || { echo "ERROR: Failed to load user-manager.sh"; exit 1; }
source "$LIB_DIR/reference-db.sh" source "$LIB_DIR/reference-db.sh" || { echo "ERROR: Failed to load reference-db.sh"; exit 1; }
# Color codes # Color codes
RED='\033[0;31m' RED='\033[0;31m'
@@ -627,10 +627,14 @@ handle_email_menu() {
############################################################################# #############################################################################
init_directories() { init_directories() {
mkdir -p "$MODULES_DIR"/{security,website,performance,backup,diagnostics,maintenance,email} mkdir -p "$MODULES_DIR"/{security,website,performance,backup,diagnostics,maintenance,email} || {
mkdir -p "$LIB_DIR" "$CONFIG_DIR" "$BASE_DIR/logs" echo "ERROR: Failed to create module directories"; return 1
touch "$CONFIG_DIR/whitelist-ips.txt" 2>/dev/null }
touch "$CONFIG_DIR/whitelist-user-agents.txt" 2>/dev/null mkdir -p "$LIB_DIR" "$CONFIG_DIR" "$BASE_DIR/logs" || {
echo "ERROR: Failed to create base directories"; return 1
}
touch "$CONFIG_DIR/whitelist-ips.txt" 2>/dev/null || true
touch "$CONFIG_DIR/whitelist-user-agents.txt" 2>/dev/null || true
} }
startup_detection() { startup_detection() {
@@ -675,7 +679,7 @@ startup_detection() {
echo "" echo ""
# Read from terminal (use /dev/tty directly) # Read from terminal (use /dev/tty directly)
read -p "Press Enter to continue..." 2>/dev/null </dev/tty || true read -p "Press Enter to continue..." </dev/tty || true
fi fi
} }
@@ -691,7 +695,7 @@ main() {
show_main_menu show_main_menu
# Read from terminal (use /dev/tty directly for interaction) # Read from terminal (use /dev/tty directly for interaction)
if ! read -r choice 2>/dev/null </dev/tty; then if ! read -r choice </dev/tty 2>/dev/null; then
# No terminal available, return from function gracefully # No terminal available, return from function gracefully
return 0 return 0
fi fi
+1 -1
View File
@@ -11,7 +11,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Fix HISTFILE if set to non-existent path (prevents crashes on sourcing) # Fix HISTFILE if set to non-existent path (prevents crashes on sourcing)
if [ -n "$HISTFILE" ]; then if [ -n "$HISTFILE" ]; then
HISTFILE_DIR="$(dirname "$HISTFILE" 2>/dev/null)" HISTFILE_DIR="$(dirname "$HISTFILE" 2>/dev/null)"
if [ ! -d "$HISTFILE_DIR" ] 2>/dev/null; then if [ ! -d "$HISTFILE_DIR" ]; then
# Fallback to default history location # Fallback to default history location
export HISTFILE="$HOME/.bash_history" export HISTFILE="$HOME/.bash_history"
fi fi