murtaza-2007 commited on
Commit ·
bd46f58
1
Parent(s): 9cb8eaf
Surface Firestore init error via /health for diagnostics
Browse files- RAG_Products/api.py +2 -0
- RAG_Products/storage.py +9 -2
RAG_Products/api.py
CHANGED
|
@@ -111,6 +111,8 @@ def health():
|
|
| 111 |
"index_loaded": index_ok,
|
| 112 |
"llm_key_set": bool(OPENROUTER_API_KEY),
|
| 113 |
"detail": detail,
|
|
|
|
|
|
|
| 114 |
}
|
| 115 |
|
| 116 |
|
|
|
|
| 111 |
"index_loaded": index_ok,
|
| 112 |
"llm_key_set": bool(OPENROUTER_API_KEY),
|
| 113 |
"detail": detail,
|
| 114 |
+
"storage_backend": storage.backend(),
|
| 115 |
+
"storage_init_error": storage.init_error(),
|
| 116 |
}
|
| 117 |
|
| 118 |
|
RAG_Products/storage.py
CHANGED
|
@@ -29,6 +29,7 @@ _COLLECTION = "chats"
|
|
| 29 |
_lock = threading.Lock()
|
| 30 |
_db = None # Firestore client (or None -> local file)
|
| 31 |
_backend = "local"
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
def _now():
|
|
@@ -37,7 +38,7 @@ def _now():
|
|
| 37 |
|
| 38 |
def _init():
|
| 39 |
"""Initialise Firestore if credentials are available; else local file."""
|
| 40 |
-
global _db, _backend
|
| 41 |
if _db is not None or _backend == "firestore":
|
| 42 |
return
|
| 43 |
if FIREBASE_CREDENTIALS or FIREBASE_CREDENTIALS_JSON:
|
|
@@ -57,10 +58,16 @@ def _init():
|
|
| 57 |
_backend = "firestore"
|
| 58 |
return
|
| 59 |
except Exception as e: # fall back rather than crash
|
| 60 |
-
|
|
|
|
| 61 |
_backend = "local"
|
| 62 |
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
def backend() -> str:
|
| 65 |
_init()
|
| 66 |
return _backend
|
|
|
|
| 29 |
_lock = threading.Lock()
|
| 30 |
_db = None # Firestore client (or None -> local file)
|
| 31 |
_backend = "local"
|
| 32 |
+
_init_error = None # last Firestore init exception, surfaced via /health
|
| 33 |
|
| 34 |
|
| 35 |
def _now():
|
|
|
|
| 38 |
|
| 39 |
def _init():
|
| 40 |
"""Initialise Firestore if credentials are available; else local file."""
|
| 41 |
+
global _db, _backend, _init_error
|
| 42 |
if _db is not None or _backend == "firestore":
|
| 43 |
return
|
| 44 |
if FIREBASE_CREDENTIALS or FIREBASE_CREDENTIALS_JSON:
|
|
|
|
| 58 |
_backend = "firestore"
|
| 59 |
return
|
| 60 |
except Exception as e: # fall back rather than crash
|
| 61 |
+
_init_error = f"{type(e).__name__}: {e}"
|
| 62 |
+
print(f"[storage] Firestore init failed ({_init_error}); using local file.")
|
| 63 |
_backend = "local"
|
| 64 |
|
| 65 |
|
| 66 |
+
def init_error():
|
| 67 |
+
"""Last Firestore init exception (for /health diagnostics), or None."""
|
| 68 |
+
return _init_error
|
| 69 |
+
|
| 70 |
+
|
| 71 |
def backend() -> str:
|
| 72 |
_init()
|
| 73 |
return _backend
|