fix: try/except around DB queries (Agent 2 review)
This commit is contained in:
parent
a440887028
commit
5b1fb8e564
@ -10,7 +10,8 @@ db = DBPools()
|
||||
dbname = get_module_dbname('rag')
|
||||
|
||||
rows = []
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
try:
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
if folder_id:
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT id, file_name, file_type, file_size, file_path, status, chunk_count, created_at FROM documents WHERE kb_id=${kb_id}$ AND folder_id=${folder_id}$ ORDER BY created_at DESC",
|
||||
@ -30,6 +31,8 @@ async with db.sqlorContext(dbname) as sor:
|
||||
"chunk_count": r.chunk_count or 0,
|
||||
"created_at": str(r.created_at)[:16] if r.created_at else ''
|
||||
})
|
||||
except:
|
||||
return json.dumps({"widgettype": "Text", "options": {"text": "加载文件列表失败", "cfontsize": 14, "color": "#e74c3c", "halign": "center", "marginTop": "40px"}}, ensure_ascii=False)
|
||||
|
||||
def fmt_size(sz):
|
||||
if sz < 1024: return str(sz) + "B"
|
||||
|
||||
@ -3,7 +3,8 @@ id = ns.get('id')
|
||||
kb_id = ns.get('kb_id', '')
|
||||
db = DBPools()
|
||||
dbname = get_module_dbname('rag')
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
try:
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
if not id:
|
||||
recs = await sor.sqlExe(
|
||||
"SELECT id, '' as parentid, content as label FROM document_chunks WHERE kb_id=${kb_id}$ AND chunk_type='directory' AND (description IS NULL OR description='') ORDER BY content",
|
||||
@ -17,4 +18,6 @@ async with db.sqlorContext(dbname) as sor:
|
||||
"SELECT id, description as parentid, content as label FROM document_chunks WHERE kb_id=${kb_id}$ AND chunk_type='directory' AND description=${id}$ ORDER BY content",
|
||||
{"kb_id": kb_id, "id": id})
|
||||
return [dict(r) for r in recs]
|
||||
except:
|
||||
return [{"id": "__root__", "parentid": "", "label": "📁 根目录(加载失败)"}]
|
||||
return []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user