-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart.py
More file actions
176 lines (153 loc) · 5.69 KB
/
start.py
File metadata and controls
176 lines (153 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
"""
JetStream Startup Wrapper with Enhanced Error Reporting
Run this instead of uvicorn to see detailed startup errors.
"""
import sys
import os
import traceback
import logging
import platform
# Fix Windows console encoding for Unicode support
if sys.platform == 'win32':
import codecs
sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict')
sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict')
os.environ['PYTHONIOENCODING'] = 'utf-8'
# Configure logging FIRST
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler(sys.stdout),
logging.FileHandler('jetstream_startup.log')
]
)
logger = logging.getLogger(__name__)
def main():
"""Start JetStream with detailed error reporting."""
print("\n" + "="*70)
print(" JetStream Startup - Enhanced Diagnostics")
print("="*70 + "\n")
# Step 1: Check working directory
logger.info(f"Working Directory: {os.getcwd()}")
logger.info(f"Python Version: {sys.version}")
logger.info(f"Platform: {sys.platform} ({platform.machine()}, {platform.architecture()[0]})")
# Verify we're in the right directory
if not os.path.exists('jetstream'):
logger.error("ERROR: 'jetstream' folder not found!")
logger.error("You must run this from the jetstream project directory.")
logger.error(f"Current directory: {os.getcwd()}")
logger.error("\nExample:")
logger.error(" cd C:\\Users\\YourName\\jetstream")
logger.error(" python start.py")
return 1
# Step 2: Test imports one by one
print("\n[1/6] Testing core imports...")
try:
import fastapi
logger.info(f"[OK] FastAPI {fastapi.__version__}")
except Exception as e:
logger.error(f"[FAIL] FastAPI import failed: {e}")
traceback.print_exc()
return 1
try:
import uvicorn
logger.info(f"[OK] Uvicorn {uvicorn.__version__}")
except Exception as e:
logger.error(f"[FAIL] Uvicorn import failed: {e}")
traceback.print_exc()
return 1
try:
import sqlalchemy
logger.info(f"[OK] SQLAlchemy {sqlalchemy.__version__}")
except Exception as e:
logger.error(f"[FAIL] SQLAlchemy import failed: {e}")
traceback.print_exc()
return 1
# Step 3: Test config import
print("\n[2/6] Loading configuration...")
try:
from jetstream.config import settings
logger.info(f"[OK] Config loaded")
logger.info(f" - Host: {settings.HOST}")
logger.info(f" - Port: {settings.PORT}")
logger.info(f" - Database: {settings.DATABASE_URL}")
except Exception as e:
logger.error(f"[FAIL] Config import failed: {e}")
traceback.print_exc()
return 1
# Step 4: Test database module import
print("\n[3/6] Testing database module...")
try:
from jetstream import database
logger.info(f"[OK] Database module imported")
except Exception as e:
logger.error(f"[FAIL] Database module import failed: {e}")
traceback.print_exc()
return 1
# Step 5: Test database initialization
print("\n[4/6] Initializing database...")
try:
from jetstream.database import init_db
init_db()
logger.info(f"[OK] Database initialized")
# Check if file was created
if os.path.exists('jetstream.db'):
size = os.path.getsize('jetstream.db')
logger.info(f"[OK] Database file exists: jetstream.db ({size} bytes)")
else:
logger.warning(f"[WARN] Database file not found at: {os.path.abspath('jetstream.db')}")
except Exception as e:
logger.error(f"[FAIL] Database initialization failed: {e}")
traceback.print_exc()
logger.error("\nDatabase Error Details:")
logger.error(f" - Attempted location: {os.path.abspath('jetstream.db')}")
logger.error(f" - Current directory: {os.getcwd()}")
logger.error(f" - Write permissions: {os.access('.', os.W_OK)}")
return 1
# Step 6: Test full app import
print("\n[5/6] Importing FastAPI application...")
try:
from jetstream.main import app
logger.info(f"[OK] FastAPI app imported successfully")
except Exception as e:
logger.error(f"[FAIL] App import failed: {e}")
traceback.print_exc()
return 1
# Step 7: Start uvicorn
print("\n[6/6] Starting Uvicorn server...")
print("="*70)
print(" If the server starts successfully, you should see:")
print(" - 'Application startup complete.'")
print(" - Browser should auto-open (if enabled)")
print(" - You should be able to access http://localhost:8000")
print("="*70 + "\n")
try:
import uvicorn
uvicorn.run(
"jetstream.main:app",
host=settings.HOST,
port=settings.PORT,
reload=False, # Disabled for cleaner diagnostic output
log_level="debug",
access_log=True
)
except Exception as e:
logger.error(f"[FAIL] Uvicorn failed to start: {e}")
traceback.print_exc()
return 1
return 0
if __name__ == "__main__":
try:
exit_code = main()
sys.exit(exit_code)
except KeyboardInterrupt:
print("\n\nShutdown requested by user")
sys.exit(0)
except Exception as e:
logger.critical(f"CRITICAL ERROR: {e}")
traceback.print_exc()
print("\n" + "="*70)
print(" STARTUP FAILED - See jetstream_startup.log for full details")
print("="*70)
sys.exit(1)