JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix(cron): display error when pushing message to feishu with wrong conifg
xiaotian077fda4c61641a0
diff --git a/jiuwenswarm/gateway/channel_manager/channel_manager.py b/jiuwenswarm/gateway/channel_manager/channel_manager.pyindex 3ae62d022a..5886183532 100644--- a/jiuwenswarm/gateway/channel_manager/channel_manager.py+++ b/jiuwenswarm/gateway/channel_manager/channel_manager.py@@ -6,6 +6,7 @@ from __future__ import annotationsimport loggingimport asyncio+import timefrom abc import ABCfrom typing import TYPE_CHECKING, Any, Awaitable, Callable@@ -156,6 +157,8 @@ class ChannelManager(ABC):await channel.send(msg)except Exception as e:logger.error("send to channel %s: %s", msg.channel_id, e, exc_info=True)+ if msg.id and msg.id.startswith("cron-push-"):+ await self._notify_cron_delivery_error(msg, e)else:logger.warning("[ChannelManager] 未找到 Channel,丢弃 robot_messages: channel_id=%s id=%s",@@ -164,6 +167,31 @@ class ChannelManager(ABC):except asyncio.CancelledError:break+ async def _notify_cron_delivery_error(self, original_msg: "Message", error: Exception) -> None:+ """推送失败时,通过 web channel 发送 chat.error 通知前端。"""+ from jiuwenswarm.common.schema.message import EventType, Message++ cron_info = (original_msg.payload or {}).get("cron", {})+ job_name = cron_info.get("job_name", "")+ error_text = f"定时任务「{job_name}」推送到 {original_msg.channel_id} 失败:{error}"+ error_msg = Message(+ id=f"cron-delivery-error-{original_msg.id}",+ type="event",+ channel_id="web",+ session_id=original_msg.session_id,+ params={},+ timestamp=time.time(),+ ok=False,+ payload={"event_type": "chat.error", "error": error_text},+ event_type=EventType.CHAT_ERROR,+ )+ web_channel = self._channels.get("web")+ if web_channel:+ try:+ await web_channel.send(error_msg)+ except Exception:+ logger.warning("[ChannelManager] 发送 cron 推送失败通知到 web 也失败了")+async def start_dispatch(self) -> None:"""启动出队派发任务(消费 MessageHandler.robot_messages 并发送到各 Channel)."""if self._dispatch_task is not None:diff --git a/jiuwenswarm/gateway/channel_manager/im_platforms/feishu/feishu_connect.py b/jiuwenswarm/gateway/channel_manager/im_platforms/feishu/feishu_connect.pyindex 589644f64f..c5180949d5 100644--- a/jiuwenswarm/gateway/channel_manager/im_platforms/feishu/feishu_connect.py+++ b/jiuwenswarm/gateway/channel_manager/im_platforms/feishu/feishu_connect.py@@ -1543,6 +1543,7 @@ class FeishuChannel(BaseChannel):except Exception as e:logger.error(f"发送飞书消息时发生异常: {e}")+ raisedef _detect_workspace_files(self, text: str) -> list[str]:"""从文本中提取 workspace 下实际存在的文件路径。@@ -2781,7 +2782,8 @@ class FeishuChannel(BaseChannel):) -> None:"""构建并发送飞书消息(在线程池中执行同步 SDK 调用,支持重试)。"""loop = asyncio.get_running_loop()-+ last_error: Exception | None = None+for attempt in range(request.max_retries):try:def _do_send():@@ -2810,6 +2812,9 @@ class FeishuChannel(BaseChannel):response.code,response.msg,)+ last_error = RuntimeError(+ f"飞书发送消息失败: code={response.code} msg={response.msg}"+ )if attempt < request.max_retries - 1:await asyncio.sleep(1 * (attempt + 1))continue@@ -2817,7 +2822,7 @@ class FeishuChannel(BaseChannel):logger.info("飞书消息发送成功: msg_type=%s%s", request.msg_type,f" {request.log_label}" if request.log_label else "")return-+except Exception as e:logger.warning("飞书发送消息异常 (尝试 %d/%d, msg_type=%s%s): %s",@@ -2826,11 +2831,13 @@ class FeishuChannel(BaseChannel):f" {request.log_label}" if request.log_label else "",e,)+ last_error = eif attempt < request.max_retries - 1:await asyncio.sleep(1 * (attempt + 1))continue- else:- logger.error("发送飞书消息异常: %s", e)++ if last_error is not None:+ raise last_errorasync def _send_image_message(self,