fix: stop excel fallback to openclaw and harden workbook save
This commit is contained in:
parent
bfe3f168a2
commit
20d45b5f1d
@ -2318,8 +2318,8 @@ class OpenClawDingTalkBot(ChatbotHandler):
|
||||
stderr_text = (proc.stderr or "").strip()
|
||||
if proc.returncode != 0 or not os.path.exists(output_path):
|
||||
detail = stderr_text or stdout_text or "未知错误"
|
||||
self.logger.error("excel converter failed code=%s detail=%s", proc.returncode, detail[:800])
|
||||
return f"Excel 转换失败:{detail[:500]}", False
|
||||
self.logger.error("excel converter failed code=%s detail=%s", proc.returncode, detail[:2500])
|
||||
return f"Excel 转换失败:{detail[:1200]}", False
|
||||
|
||||
summary_line = ""
|
||||
for line in stdout_text.splitlines():
|
||||
@ -2584,17 +2584,18 @@ class OpenClawDingTalkBot(ChatbotHandler):
|
||||
context_text = image_context_result.get("context_text", "")
|
||||
if context_text:
|
||||
prompt_for_exec = self._merge_prompt_with_image_context(prompt, context_text)
|
||||
if self._is_install_media_prompt(prompt):
|
||||
answer = await asyncio.to_thread(self._run_install_media_lookup, prompt)
|
||||
elif self._is_dalongxia_analytics_prompt(prompt):
|
||||
answer = await asyncio.to_thread(self._run_dalongxia_analytics, prompt)
|
||||
elif self._is_video_analysis_prompt(prompt):
|
||||
answer = await asyncio.to_thread(self._run_video_analysis, prompt)
|
||||
elif self._is_market_prompt(prompt):
|
||||
subject = self._extract_market_subject(prompt)
|
||||
answer = await asyncio.to_thread(self._run_market_brief, subject)
|
||||
else:
|
||||
answer = await asyncio.to_thread(self._run_openclaw, session_id, prompt_for_exec)
|
||||
if not has_excel_file:
|
||||
if self._is_install_media_prompt(prompt):
|
||||
answer = await asyncio.to_thread(self._run_install_media_lookup, prompt)
|
||||
elif self._is_dalongxia_analytics_prompt(prompt):
|
||||
answer = await asyncio.to_thread(self._run_dalongxia_analytics, prompt)
|
||||
elif self._is_video_analysis_prompt(prompt):
|
||||
answer = await asyncio.to_thread(self._run_video_analysis, prompt)
|
||||
elif self._is_market_prompt(prompt):
|
||||
subject = self._extract_market_subject(prompt)
|
||||
answer = await asyncio.to_thread(self._run_market_brief, subject)
|
||||
else:
|
||||
answer = await asyncio.to_thread(self._run_openclaw, session_id, prompt_for_exec)
|
||||
except Exception:
|
||||
self.logger.exception("worker execution failed: session=%s", session_id)
|
||||
answer = "系统执行异常,请稍后重试。"
|
||||
|
||||
@ -307,6 +307,26 @@ def process_sheet(sheet, args: argparse.Namespace, ssl_context, temp_files: list
|
||||
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:
|
||||
args = parse_args()
|
||||
|
||||
@ -333,7 +353,14 @@ def main() -> int:
|
||||
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
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:
|
||||
for file_path in temp_files:
|
||||
file_path.unlink(missing_ok=True)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user