Add detailed error logging to diagnose backend startup issues
Browse filesBackend still failing to start on port 8000. Added comprehensive
error handling and logging to see exactly what's failing.
Changes:
- Wrap all imports in try/except with detailed error logging
- Print full tracebacks when imports fail
- Backend will start even if prompt imports fail
- Fallback prompts ensure functionality continues
- Clear logging shows which prompts loaded successfully
This will help diagnose:
- Which specific import is failing (prompts vs docs_manager)
- Full error traceback for debugging
- Backend will start regardless, allowing frontend to connect
- Logs will show: [Startup] messages with ✅ success or ❌ errors
After deploying, check logs for:
'[Startup] ✅' messages = success
'[Startup] ⚠️' messages = partial failure with fallback
'[Startup] ❌' messages = complete failure with minimal fallback
- backend_api.py +47 -18
|
@@ -20,24 +20,53 @@ from huggingface_hub import InferenceClient
|
|
| 20 |
import httpx
|
| 21 |
|
| 22 |
# Import system prompts for code generation
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
print("[Startup]
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# Define models and languages here to avoid importing Gradio UI
|
| 43 |
AVAILABLE_MODELS = [
|
|
|
|
| 20 |
import httpx
|
| 21 |
|
| 22 |
# Import system prompts for code generation
|
| 23 |
+
# Use try/except to handle import failures gracefully
|
| 24 |
+
print("[Startup] Loading system prompts...")
|
| 25 |
+
|
| 26 |
+
try:
|
| 27 |
+
from anycoder_app.prompts import (
|
| 28 |
+
HTML_SYSTEM_PROMPT,
|
| 29 |
+
TRANSFORMERS_JS_SYSTEM_PROMPT,
|
| 30 |
+
STREAMLIT_SYSTEM_PROMPT,
|
| 31 |
+
REACT_SYSTEM_PROMPT,
|
| 32 |
+
GENERIC_SYSTEM_PROMPT
|
| 33 |
+
)
|
| 34 |
+
print("[Startup] ✅ Loaded basic prompts from anycoder_app.prompts")
|
| 35 |
+
|
| 36 |
+
# Try to initialize dynamic Gradio and ComfyUI system prompts with full API docs
|
| 37 |
+
try:
|
| 38 |
+
from anycoder_app.docs_manager import update_gradio_system_prompts, update_json_system_prompts
|
| 39 |
+
print("[Startup] Initializing Gradio and ComfyUI prompts with API documentation...")
|
| 40 |
+
update_gradio_system_prompts()
|
| 41 |
+
update_json_system_prompts()
|
| 42 |
+
|
| 43 |
+
# Import the now-populated prompts
|
| 44 |
+
from anycoder_app.prompts import GRADIO_SYSTEM_PROMPT, JSON_SYSTEM_PROMPT
|
| 45 |
+
print("[Startup] ✅ All system prompts loaded successfully with full API documentation")
|
| 46 |
+
except Exception as e:
|
| 47 |
+
import traceback
|
| 48 |
+
print(f"[Startup] ⚠️ Failed to load dynamic Gradio/ComfyUI prompts: {e}")
|
| 49 |
+
print(f"[Startup] Traceback: {traceback.format_exc()}")
|
| 50 |
+
print("[Startup] Using basic fallback prompts for Gradio and ComfyUI")
|
| 51 |
+
GRADIO_SYSTEM_PROMPT = "You are an expert Gradio developer. Create complete, working Gradio applications with proper documentation."
|
| 52 |
+
JSON_SYSTEM_PROMPT = "You are an expert at generating JSON configurations. Create valid, well-structured JSON for ComfyUI workflows."
|
| 53 |
+
|
| 54 |
+
except Exception as e:
|
| 55 |
+
import traceback
|
| 56 |
+
print(f"[Startup] ❌ ERROR: Could not import from anycoder_app: {e}")
|
| 57 |
+
print(f"[Startup] Traceback: {traceback.format_exc()}")
|
| 58 |
+
print("[Startup] Using minimal fallback prompts - functionality will be limited")
|
| 59 |
+
|
| 60 |
+
# Define minimal fallback prompts to allow backend to start
|
| 61 |
+
HTML_SYSTEM_PROMPT = "You are an expert web developer. Create complete HTML applications with CSS and JavaScript."
|
| 62 |
+
TRANSFORMERS_JS_SYSTEM_PROMPT = "You are an expert at creating transformers.js applications. Generate complete working code."
|
| 63 |
+
STREAMLIT_SYSTEM_PROMPT = "You are an expert Streamlit developer. Create complete Streamlit applications."
|
| 64 |
+
REACT_SYSTEM_PROMPT = "You are an expert React developer. Create complete React applications with Next.js."
|
| 65 |
+
GRADIO_SYSTEM_PROMPT = "You are an expert Gradio developer. Create complete, working Gradio applications."
|
| 66 |
+
JSON_SYSTEM_PROMPT = "You are an expert at generating JSON configurations. Create valid, well-structured JSON."
|
| 67 |
+
GENERIC_SYSTEM_PROMPT = "You are an expert {language} developer. Create complete, working {language} applications."
|
| 68 |
+
|
| 69 |
+
print("[Startup] System prompts initialization complete")
|
| 70 |
|
| 71 |
# Define models and languages here to avoid importing Gradio UI
|
| 72 |
AVAILABLE_MODELS = [
|