Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Catching a bare
Exceptioninside the polling loop may mask programming/operational errors; consider narrowing this to the specific exception(s) expected from the poll call, or at least excludingasyncio.CancelledErrorand other critical exceptions. - Instead of logging only
ein the error message, consider usinglogger.exception(or includingexc_info=True) so that the full traceback is available for diagnosing repeated polling failures.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Catching a bare `Exception` inside the polling loop may mask programming/operational errors; consider narrowing this to the specific exception(s) expected from the poll call, or at least excluding `asyncio.CancelledError` and other critical exceptions.
- Instead of logging only `e` in the error message, consider using `logger.exception` (or including `exc_info=True`) so that the full traceback is available for diagnosing repeated polling failures.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request introduces error handling for the inbound long-poll process in the WeChat Official Account adapter, ensuring that polling failures are logged and retried after a 5-second delay instead of crashing. Feedback suggests using logger.exception to capture full tracebacks for better debugging and replacing the hardcoded retry delay with a named constant to improve code maintainability.
| logger.error( | ||
| "weixin_oc(%s): poll inbound updates failed, will retry after 5 seconds: %s", | ||
| self.meta().id, | ||
| e, | ||
| ) |
There was a problem hiding this comment.
Using logger.exception here will provide a full traceback in the logs, which is very helpful for debugging the root cause of the polling failure. It's generally a good practice to log the full exception context for unexpected errors, even if they are being retried. logger.exception automatically includes exception information and should be used within an except block.
logger.exception(
"weixin_oc(%s): poll inbound updates failed, will retry after 5 seconds",
self.meta().id,
)| self.meta().id, | ||
| e, | ||
| ) | ||
| await asyncio.sleep(5) |
fixes: #7022
Modifications / 改动点
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Bug Fixes: