Spaces:
Sleeping
Sleeping
Add logging and error handling infrastructure to app.py
Browse files- Added logging configuration with INFO level
- Added traceback import for detailed error reporting
- Created safe_wrapper utility function for error handling
- Sets foundation for wrapping event handlers with try-catch blocks
app.py
CHANGED
|
@@ -6,12 +6,34 @@ from typing import List, Dict, Any, Optional
|
|
| 6 |
from pathlib import Path
|
| 7 |
from linkedin_data import fetch_linkedin_profile, get_cache_stats
|
| 8 |
from data_enrichment import DataEnrichmentManager
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# --- Data Storage Configuration ---
|
| 11 |
DATA_DIR = Path("/data")
|
| 12 |
USER_DATA_DIR = DATA_DIR / "users"
|
| 13 |
USER_DATA_DIR.mkdir(parents=True, exist_ok=True)
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def get_user_dir(username: str) -> Path:
|
| 16 |
"""Get or create user-specific data directory"""
|
| 17 |
user_dir = USER_DATA_DIR / username
|
|
|
|
| 6 |
from pathlib import Path
|
| 7 |
from linkedin_data import fetch_linkedin_profile, get_cache_stats
|
| 8 |
from data_enrichment import DataEnrichmentManager
|
| 9 |
+
import logging
|
| 10 |
+
import traceback
|
| 11 |
|
| 12 |
# --- Data Storage Configuration ---
|
| 13 |
DATA_DIR = Path("/data")
|
| 14 |
USER_DATA_DIR = DATA_DIR / "users"
|
| 15 |
USER_DATA_DIR.mkdir(parents=True, exist_ok=True)
|
| 16 |
|
| 17 |
+
# --- Logging Configuration ---
|
| 18 |
+
logging.basicConfig(
|
| 19 |
+
level=logging.INFO,
|
| 20 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
| 21 |
+
)
|
| 22 |
+
logger = logging.getLogger(__name__)
|
| 23 |
+
|
| 24 |
+
# --- Error Handling Utilities ---
|
| 25 |
+
def safe_wrapper(func, error_message="An error occurred"):
|
| 26 |
+
"""Wrapper to safely execute functions with error handling"""
|
| 27 |
+
def wrapper(*args, **kwargs):
|
| 28 |
+
try:
|
| 29 |
+
return func(*args, **kwargs)
|
| 30 |
+
except Exception as e:
|
| 31 |
+
error_details = f"{error_message}: {str(e)}"
|
| 32 |
+
logger.error(error_details)
|
| 33 |
+
logger.error(traceback.format_exc())
|
| 34 |
+
return f"❌ {error_details}\n\nPlease try again or contact support if the issue persists."
|
| 35 |
+
return wrapper
|
| 36 |
+
|
| 37 |
def get_user_dir(username: str) -> Path:
|
| 38 |
"""Get or create user-specific data directory"""
|
| 39 |
user_dir = USER_DATA_DIR / username
|