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
19 unmodified lines20212223242526272829303132333435363738394041424319 unmodified linesimport httpx# Import system prompts for code generation# These come from anycoder_app which has all the detailed promptsfrom anycoder_app.prompts import (HTML_SYSTEM_PROMPT,TRANSFORMERS_JS_SYSTEM_PROMPT,STREAMLIT_SYSTEM_PROMPT,REACT_SYSTEM_PROMPT,GENERIC_SYSTEM_PROMPT)# Initialize dynamic Gradio and ComfyUI system prompts with full API docsfrom anycoder_app.docs_manager import update_gradio_system_prompts, update_json_system_promptsprint("[Startup] Initializing Gradio and ComfyUI system prompts with API documentation...")update_gradio_system_prompts()update_json_system_prompts()# Import the now-populated promptsfrom anycoder_app.prompts import GRADIO_SYSTEM_PROMPT, JSON_SYSTEM_PROMPTprint("[Startup] ✅ All system prompts loaded successfully with full API documentation")# Define models and languages here to avoid importing Gradio UIAVAILABLE_MODELS = [19 unmodified lines202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717219 unmodified linesimport httpx# Import system prompts for code generation# Use try/except to handle import failures gracefullyprint("[Startup] Loading system prompts...")try:from anycoder_app.prompts import (HTML_SYSTEM_PROMPT,TRANSFORMERS_JS_SYSTEM_PROMPT,STREAMLIT_SYSTEM_PROMPT,REACT_SYSTEM_PROMPT,GENERIC_SYSTEM_PROMPT)print("[Startup] ✅ Loaded basic prompts from anycoder_app.prompts")# Try to initialize dynamic Gradio and ComfyUI system prompts with full API docstry:from anycoder_app.docs_manager import update_gradio_system_prompts, update_json_system_promptsprint("[Startup] Initializing Gradio and ComfyUI prompts with API documentation...")update_gradio_system_prompts()update_json_system_prompts()# Import the now-populated promptsfrom anycoder_app.prompts import GRADIO_SYSTEM_PROMPT, JSON_SYSTEM_PROMPTprint("[Startup] ✅ All system prompts loaded successfully with full API documentation")except Exception as e:import tracebackprint(f"[Startup] ⚠️ Failed to load dynamic Gradio/ComfyUI prompts: {e}")print(f"[Startup] Traceback: {traceback.format_exc()}")print("[Startup] Using basic fallback prompts for Gradio and ComfyUI")GRADIO_SYSTEM_PROMPT = "You are an expert Gradio developer. Create complete, working Gradio applications with proper documentation."JSON_SYSTEM_PROMPT = "You are an expert at generating JSON configurations. Create valid, well-structured JSON for ComfyUI workflows."except Exception as e:import tracebackprint(f"[Startup] ❌ ERROR: Could not import from anycoder_app: {e}")print(f"[Startup] Traceback: {traceback.format_exc()}")print("[Startup] Using minimal fallback prompts - functionality will be limited")# Define minimal fallback prompts to allow backend to startHTML_SYSTEM_PROMPT = "You are an expert web developer. Create complete HTML applications with CSS and JavaScript."TRANSFORMERS_JS_SYSTEM_PROMPT = "You are an expert at creating transformers.js applications. Generate complete working code."STREAMLIT_SYSTEM_PROMPT = "You are an expert Streamlit developer. Create complete Streamlit applications."REACT_SYSTEM_PROMPT = "You are an expert React developer. Create complete React applications with Next.js."GRADIO_SYSTEM_PROMPT = "You are an expert Gradio developer. Create complete, working Gradio applications."JSON_SYSTEM_PROMPT = "You are an expert at generating JSON configurations. Create valid, well-structured JSON."GENERIC_SYSTEM_PROMPT = "You are an expert {language} developer. Create complete, working {language} applications."print("[Startup] System prompts initialization complete")# Define models and languages here to avoid importing Gradio UIAVAILABLE_MODELS = [