Enhancement: 为 man 和 textfx 指令添加图片渲染和文本 fallback #54
Reference in New Issue
Block a user
No description provided.
Delete Branch "enhancement/man-and-textfx"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
PR Type
Enhancement, Bug fix
Description
新增错误消息渲染为图片的通用模块
textfx 指令错误输出改用图片渲染
man 指令添加图片渲染失败的文本 fallback
修复
core.py文件末尾缺少换行符Diagram Walkthrough
File Walkthrough
render_error_message.py
新增错误消息图片渲染通用模块konabot/common/render_error_message.py
render_error_message函数,将错误文本渲染为图片error_report页面进行渲染__init__.py
textfx 错误输出改用图片渲染konabot/plugins/handle_text/init.py
render_error_message渲染错误信息为图片__init__.py
man 指令添加渲染失败文本 fallbackkonabot/plugins/man/init.py
playwright.async_api.Error和ConnectionError后回退发送纯文本core.py
修复文件末尾缺少换行符konabot/plugins/markdown/core.py
PR Reviewer Guide 🔍
(Review updated until commit
9c9496efbd)Here are some key observations to aid the review process:
潜在 XSS 风险:在
render_error_message.py中,用户可控的r.ostream内容被拼接进message后,通过page.evaluate传递给前端的setContent函数。如果该前端函数使用innerHTML等不安全方式渲染内容,攻击者可能通过构造恶意输入实现脚本注入。建议确认前端setContent实现中是否对输入进行了适当的 HTML 转义。错误遍历逻辑
当多个
results中存在多个错误时,循环只会渲染并发送第一个错误就return,后续错误会被静默忽略。应确认这是否是预期行为,或者是否需要汇总所有错误后一并展示给用户。XSS 风险
message字符串通过page.evaluate直接传入前端setContent函数。如果message包含用户可控内容(如r.ostream),且setContent内部使用innerHTML等方式渲染,则可能存在注入风险。应确认前端侧是否对输入做了转义处理。PR Code Suggestions ✨
Latest suggestions up to
9c9496eExplore these optional code suggestions:
页面加载超时时间可能过短
render方法内部可能也有自己的超时设置,但这里wait_for_function的 3 秒超时如果触发,会抛出playwright.async_api.TimeoutError(它是playwright.async_api.Error的子类),虽然外层能捕获,但 3秒对于页面加载来说可能偏短,容易导致频繁 fallback。建议适当增大超时时间或使其可配置。
konabot/common/render_error_message.py [18]
Suggestion importance[1-10]: 3
__
Why: The suggestion is technically valid — 3 seconds could be tight for page load in some environments, and the
TimeoutErrorwould indeed be caught by the outerexcept. However, this is a minor tuning concern rather than a bug. The current 3-second timeout is a reasonable default for a simple error rendering page, and the fallback to plain text already handles the timeout gracefully. The impact is low.Previous suggestions
Suggestions up to commit
9c9496e页面函数等待超时时间过短
timeout=1000仅为 1 秒,在高负载或冷启动场景下,页面 JS 函数可能尚未就绪就会超时,导致频繁回退到纯文本。建议适当增大超时时间(如5000ms),以提高渲染成功率。
konabot/common/render_error_message.py [18]
Suggestion importance[1-10]: 4
__
Why: The suggestion is reasonable — a 1-second timeout could be tight under cold start or high load. However, this is a minor tuning concern rather than a bug. The function already has a fallback to plain text on failure (line 31-33), so a timeout here gracefully degrades. The impact is low since the fallback behavior is already handled correctly.
Suggestions up to commit
7026337Fallback 异常捕获范围过窄
当前只捕获了
playwright.async_api.Error,但渲染过程中也可能抛出其他异常(如网络超时、连接被拒绝等非 Playwright特定异常),这会导致未被捕获的异常向上传播,用户收不到任何反馈。建议捕获更宽泛的
Exception以确保文本 fallback 始终生效。konabot/common/render_error_message.py [31-33]
Suggestion importance[1-10]: 6
__
Why: The suggestion is valid —
playwright.async_api.Errorwon't catch all possible failures during rendering (e.g.,ConnectionError,asyncio.TimeoutError). Broadening toExceptionensures the text fallback always works. However, this is a moderate error-handling improvement rather than a critical bug, since the most likely failures in a Playwright rendering path are indeed Playwright errors.Man 指令 fallback 异常捕获过窄
与
render_error_message同理,MarkDownCore.render_markdown可能抛出非playwright.async_api.Error的异常(如连接错误、超时等),导致 fallback 逻辑不会触发,用户看到的是未处理的错误。建议捕获更宽泛的Exception并记录日志。konabot/plugins/man/init.py [102-104]
Suggestion importance[1-10]: 6
__
Why: Same reasoning as suggestion 1 — catching only
playwright.async_api.Errormay miss non-Playwright exceptions, leaving the user with no response. Adding logging is also a good practice. It's a reasonable improvement but not critical, as the primary failure mode is likely a Playwright error.Persistent review updated to latest commit
9c9496efbdPersistent review updated to latest commit
9c9496efbd