refactor(lightrag): Optimize error handling and logging

‌[During operation] Failure to properly log exception details‌
- Use traceback.format_exc() to capture comprehensive error traces when processing documents
- Log verbose error context upon failures in entity/relationship extraction
- Enhance system stability and debuggability by expanding exception catching and structured logging
This commit is contained in:
stevezhang
2025-04-17 16:08:58 +08:00
parent 14b4bc96ce
commit 6a1e9baa24

View File

@@ -1,5 +1,6 @@
from __future__ import annotations
import traceback
import asyncio
import configparser
import os
@@ -959,7 +960,8 @@ class LightRAG:
)
except Exception as e:
# Log error and update pipeline status
error_msg = f"Failed to process document {doc_id}: {str(e)}"
error_msg = f"Failed to process document {doc_id}: {traceback.format_exc()}"
logger.error(error_msg)
async with pipeline_status_lock:
pipeline_status["latest_message"] = error_msg
@@ -1076,7 +1078,9 @@ class LightRAG:
llm_response_cache=self.llm_response_cache,
)
except Exception as e:
logger.error("Failed to extract entities and relationships")
logger.error(
f"Failed to extract entities and relationships : {traceback.format_exc()}"
)
raise e
async def _insert_done(