Skip to content

[Bug]网络异常时 logger.exception 字符串格式化错误导致进程致命崩溃 #76

@cznccsjd

Description

@cznccsjd

【问题描述】
在 dingtalk_stream/stream.py 的第 89 行,异常处理模块在调用 Python 标准 logging 库时,使用了错误的字符串格式化传参语法。

当 WebSocket 发生偶发网络抖动或底层协程报错时,原本应该被静默记录的异常,却因为 logger.exception('unknown exception', e) 这行代码,引发了 TypeError: not all arguments converted during string formatting 错误。这导致异常未能被妥善捕获,反而直接炸毁了调用方的整个主进程(如 Agent 的守护进程)。

【崩溃日志现场】

Python
File ".../site-packages/dingtalk_stream/stream.py", line 89, in start
self.logger.exception('unknown exception', e)
Message: 'unknown exception'
Arguments: (TypeError("'coroutine' object does not support the asynchronous context manager protocol"),)
...
TypeError: not all arguments converted during string formatting
【期望行为】
SDK 应当优雅地记录网络底层异常,而不应引发新的语法错误导致使用该 SDK 的业务进程崩溃。

【修复建议 (Fix)】
建议修改 dingtalk_stream/stream.py 第 89 行的代码,采用合法的 logging 传参格式:

Python

❌ 当前错误代码:

self.logger.exception('unknown exception', e)

✅ 建议修复为:

self.logger.exception('unknown exception: %s', e)

或者利用原生的 traceback 输出:

self.logger.exception('unknown exception', exc_info=e)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions