Skip to content

Commit 094c2de

Browse files
he-yufengSoulter
andauthored
fix: surface weixin media send failures (#8175)
* fix: surface weixin media send failures * fix: include weixin send failure context * Delete tests/unit/test_weixin_oc_adapter.py --------- Co-authored-by: Weilong Liao <37870767+Soulter@users.noreply.github.com>
1 parent 7d402fa commit 094c2de

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,12 @@ async def _send_media_segment(
993993
file_name,
994994
)
995995
except Exception as e:
996-
logger.error("weixin_oc(%s): prepare media failed: %s", self.meta().id, e)
996+
logger.error(
997+
"weixin_oc(%s): prepare media failed: %s",
998+
self.meta().id,
999+
e,
1000+
exc_info=True,
1001+
)
9971002
return False
9981003

9991004
if text:
@@ -1608,18 +1613,21 @@ async def send_by_session(
16081613
target_user = session.session_id
16091614
pending_text = ""
16101615
has_supported_segment = False
1616+
failed_segments = 0
16111617
for segment in message_chain.chain:
16121618
if isinstance(segment, Plain):
16131619
pending_text += segment.text
16141620
continue
16151621

16161622
if isinstance(segment, (Image, Video, File)):
16171623
has_supported_segment = True
1618-
await self._send_media_segment(
1624+
sent = await self._send_media_segment(
16191625
target_user,
16201626
segment,
16211627
text=pending_text.strip() or None,
16221628
)
1629+
if not sent:
1630+
failed_segments += 1
16231631
pending_text = ""
16241632
continue
16251633

@@ -1631,13 +1639,20 @@ async def send_by_session(
16311639

16321640
if pending_text:
16331641
has_supported_segment = True
1634-
await self._send_to_session(target_user, pending_text.strip())
1642+
sent = await self._send_to_session(target_user, pending_text.strip())
1643+
if not sent:
1644+
failed_segments += 1
16351645

16361646
if not has_supported_segment:
16371647
logger.warning(
16381648
"weixin_oc(%s): outbound message ignored, no supported segments",
16391649
self.meta().id,
16401650
)
1651+
if failed_segments:
1652+
raise RuntimeError(
1653+
f"weixin_oc({self.meta().id}, target_user={target_user}) "
1654+
f"failed to send {failed_segments} message segment(s)"
1655+
)
16411656
await super().send_by_session(session, message_chain)
16421657

16431658
def meta(self) -> PlatformMetadata:

0 commit comments

Comments
 (0)