fix: DOMException 错误信息丢失 —— String(e) 输出 [object DOMException] 而非真实错误消息 (#54) - #62
Merged
Merged
Conversation
…消息 (#54) - 所有 String(e) 站点改为 e instanceof Error ? e.message : String(e) 覆盖 entrypoints/content.ts、entrypoints/background.ts、src/engines/router.ts 共 7 处,确保 DOMException 的 name/message 正确展示在 toast 与日志中 - walker.ts 逐元素判定包裹 try-catch,Web Components 上 DOM 属性访问 抛异常时安全跳过当前节点,宁可漏翻单个可疑节点也不要整页崩溃 - doTranslate 增加阶段标记 [collect]/[render idx=N],缩小错误排查范围 - 版本号 0.6.19 → 0.6.20 Co-Authored-By: zhexuancai-uts <261878103+zhexuancai-uts@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复内容
1. 正确提取 DOMException 的 message(必须)
所有
String(e)站点改为e instanceof Error ? e.message : String(e),覆盖 7 处:entrypoints/content.tsentrypoints/background.tssrc/engines/router.tsDOMException继承自Error,.name与.message均已有值,但String(e)在特定 console 实现中走Object.prototype.toString路径,输出[object DOMException]而非真实错误描述。2. 为 walker 逐元素判定增加防御(推荐)
src/dom/walker.ts中的applyCompat/shouldSkipNonVisual/hasNonTextContent调用包裹在 try-catch 中。GitHub 大量 Web Components(<relative-time>、<clipboard-copy>、<include-fragment>等)上访问textContent/outerHTML的 getter 可能抛出,失败时安全跳过当前节点,宁可漏翻单个可疑节点也不要整页崩溃。3. 为 doTranslate 增加阶段标记(推荐)
collect()阶段异常标记为[collect]render()阶段异常标记为[render idx=N]即使
.message不完整也能缩小排查范围。Closes #54