From 6a1e9baa24ea25502f2f1b81b35ab3c69e5225e4 Mon Sep 17 00:00:00 2001 From: stevezhang Date: Thu, 17 Apr 2025 16:08:58 +0800 Subject: [PATCH] =?UTF-8?q?refactor(lightrag):=20Optimize=20error=20handli?= =?UTF-8?q?ng=20and=20logging=20=E2=80=8C[During=20operation]=20Failure=20?= =?UTF-8?q?to=20properly=20log=20exception=20details=E2=80=8C=20-=20Use=20?= =?UTF-8?q?traceback.format=5Fexc()=20to=20capture=20comprehensive=20error?= =?UTF-8?q?=20traces=20when=20processing=20documents=20-=20Log=20verbose?= =?UTF-8?q?=20error=20context=20upon=20failures=20in=20entity/relationship?= =?UTF-8?q?=20extraction=20-=20Enhance=20system=20stability=20and=20debugg?= =?UTF-8?q?ability=20by=20expanding=20exception=20catching=20and=20structu?= =?UTF-8?q?red=20logging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lightrag/lightrag.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lightrag/lightrag.py b/lightrag/lightrag.py index daa92435..02fe9364 100644 --- a/lightrag/lightrag.py +++ b/lightrag/lightrag.py @@ -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(