fix: stop excel fallback to openclaw and harden workbook save

This commit is contained in:
Mayorz 2026-03-04 16:20:10 +08:00
parent bfe3f168a2
commit 20d45b5f1d
2 changed files with 42 additions and 14 deletions

View File

@ -2318,8 +2318,8 @@ class OpenClawDingTalkBot(ChatbotHandler):
stderr_text = (proc.stderr or "").strip() stderr_text = (proc.stderr or "").strip()
if proc.returncode != 0 or not os.path.exists(output_path): if proc.returncode != 0 or not os.path.exists(output_path):
detail = stderr_text or stdout_text or "未知错误" detail = stderr_text or stdout_text or "未知错误"
self.logger.error("excel converter failed code=%s detail=%s", proc.returncode, detail[:800]) self.logger.error("excel converter failed code=%s detail=%s", proc.returncode, detail[:2500])
return f"Excel 转换失败:{detail[:500]}", False return f"Excel 转换失败:{detail[:1200]}", False
summary_line = "" summary_line = ""
for line in stdout_text.splitlines(): for line in stdout_text.splitlines():
@ -2584,17 +2584,18 @@ class OpenClawDingTalkBot(ChatbotHandler):
context_text = image_context_result.get("context_text", "") context_text = image_context_result.get("context_text", "")
if context_text: if context_text:
prompt_for_exec = self._merge_prompt_with_image_context(prompt, context_text) prompt_for_exec = self._merge_prompt_with_image_context(prompt, context_text)
if self._is_install_media_prompt(prompt): if not has_excel_file:
answer = await asyncio.to_thread(self._run_install_media_lookup, prompt) if self._is_install_media_prompt(prompt):
elif self._is_dalongxia_analytics_prompt(prompt): answer = await asyncio.to_thread(self._run_install_media_lookup, prompt)
answer = await asyncio.to_thread(self._run_dalongxia_analytics, prompt) elif self._is_dalongxia_analytics_prompt(prompt):
elif self._is_video_analysis_prompt(prompt): answer = await asyncio.to_thread(self._run_dalongxia_analytics, prompt)
answer = await asyncio.to_thread(self._run_video_analysis, prompt) elif self._is_video_analysis_prompt(prompt):
elif self._is_market_prompt(prompt): answer = await asyncio.to_thread(self._run_video_analysis, prompt)
subject = self._extract_market_subject(prompt) elif self._is_market_prompt(prompt):
answer = await asyncio.to_thread(self._run_market_brief, subject) subject = self._extract_market_subject(prompt)
else: answer = await asyncio.to_thread(self._run_market_brief, subject)
answer = await asyncio.to_thread(self._run_openclaw, session_id, prompt_for_exec) else:
answer = await asyncio.to_thread(self._run_openclaw, session_id, prompt_for_exec)
except Exception: except Exception:
self.logger.exception("worker execution failed: session=%s", session_id) self.logger.exception("worker execution failed: session=%s", session_id)
answer = "系统执行异常,请稍后重试。" answer = "系统执行异常,请稍后重试。"

View File

@ -307,6 +307,26 @@ def process_sheet(sheet, args: argparse.Namespace, ssl_context, temp_files: list
return results return results
def drop_broken_images(workbook) -> int:
removed = 0
for sheet in workbook.worksheets:
existing = list(getattr(sheet, "_images", []))
if not existing:
continue
kept = []
removed_in_sheet = 0
for image in existing:
try:
image._data()
kept.append(image)
except Exception:
removed += 1
removed_in_sheet += 1
if removed_in_sheet:
sheet._images = kept
return removed
def main() -> int: def main() -> int:
args = parse_args() args = parse_args()
@ -333,7 +353,14 @@ def main() -> int:
output_path.parent.mkdir(parents=True, exist_ok=True) output_path.parent.mkdir(parents=True, exist_ok=True)
try: try:
workbook.save(output_path) try:
workbook.save(output_path)
except Exception as save_error:
removed = drop_broken_images(workbook)
if removed <= 0:
raise
print(f"WARN: dropped_broken_images={removed} reason={save_error}")
workbook.save(output_path)
finally: finally:
for file_path in temp_files: for file_path in temp_files:
file_path.unlink(missing_ok=True) file_path.unlink(missing_ok=True)