fix(weixin): raise exceptions instead of silently dropping messages

_send_text() swallowed API errors (non-zero errcode) with just a
warning log, and send() had three silent return paths (no client,
session paused, no context_token). Neither triggered ChannelManager's
retry logic, causing persistent message loss until a new inbound
message refreshed the context_token.

Now all failure paths raise RuntimeError, matching BaseChannel's
contract and enabling proper retry behavior.
This commit is contained in:
chengyongru
2026-05-06 23:52:50 +08:00
committed by Xubin Ren
parent 4efd904ccc
commit 98c2f7cc27
2 changed files with 51 additions and 22 deletions
+6 -14
View File
@@ -940,12 +940,8 @@ class WeixinChannel(BaseChannel):
async def send(self, msg: OutboundMessage) -> None:
if not self._client or not self._token:
self.logger.warning("client not initialized or not authenticated")
return
try:
self._assert_session_active()
except RuntimeError:
return
raise RuntimeError("WeChat client not initialized or not authenticated")
self._assert_session_active()
is_progress = bool((msg.metadata or {}).get("_progress", False))
if not is_progress:
@@ -954,11 +950,9 @@ class WeixinChannel(BaseChannel):
content = msg.content.strip()
ctx_token = self._context_tokens.get(msg.chat_id, "")
if not ctx_token:
self.logger.warning(
"no context_token for chat_id={}, cannot send",
msg.chat_id,
raise RuntimeError(
f"No context_token for chat_id={msg.chat_id}, cannot send"
)
return
typing_ticket = ""
with suppress(Exception):
@@ -1128,10 +1122,8 @@ class WeixinChannel(BaseChannel):
data = await self._api_post("ilink/bot/sendmessage", body)
errcode = data.get("errcode", 0)
if errcode and errcode != 0:
self.logger.warning(
"send error (code {}): {}",
errcode,
data.get("errmsg", ""),
raise RuntimeError(
f"WeChat send text error (code {errcode}): {data.get('errmsg', '')}"
)
async def _send_media_file(