mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
fix: improve error handling for knowledge base upload (#7536)
* fix: improve error handling for knowledge base upload - Log details field in KnowledgeBaseUploadError for better debugging - Distinguish between empty pre-chunked text and empty chunking result with appropriate error messages * style: format code
This commit is contained in:
@@ -329,11 +329,20 @@ class KBHelper:
|
||||
) from exc
|
||||
|
||||
if not chunks_text or not any(chunk.strip() for chunk in chunks_text):
|
||||
raise KnowledgeBaseUploadError(
|
||||
stage="chunking",
|
||||
user_message=("分块失败:文档内容为空,未生成任何可索引文本块。"),
|
||||
details={"file_name": file_name},
|
||||
)
|
||||
if pre_chunked_text is not None:
|
||||
raise KnowledgeBaseUploadError(
|
||||
stage="validation",
|
||||
user_message=("预分块文本为空,未提供任何可索引文本块。"),
|
||||
details={"file_name": file_name},
|
||||
)
|
||||
else:
|
||||
raise KnowledgeBaseUploadError(
|
||||
stage="chunking",
|
||||
user_message=(
|
||||
"分块失败:文档内容为空,未生成任何可索引文本块。"
|
||||
),
|
||||
details={"file_name": file_name},
|
||||
)
|
||||
|
||||
contents = []
|
||||
metadatas = []
|
||||
@@ -423,7 +432,7 @@ class KBHelper:
|
||||
return doc
|
||||
except Exception as e:
|
||||
if isinstance(e, KnowledgeBaseUploadError):
|
||||
logger.warning(f"上传文档失败: {e}")
|
||||
logger.warning(f"上传文档失败: {e}", extra={"details": e.details})
|
||||
else:
|
||||
logger.error(f"上传文档失败: {e}", exc_info=True)
|
||||
# if file_path.exists():
|
||||
|
||||
Reference in New Issue
Block a user