Fix braille crash when zh-tw.ctb cannot translate Chinese text#50
Fix braille crash when zh-tw.ctb cannot translate Chinese text#50
Conversation
Wrap braille display calls in message() with a try-except to gracefully handle RuntimeError from liblouis when it fails to translate Chinese characters (e.g. with the zh-tw.ctb table). Speech output is unaffected; braille output is silently skipped with a debug log entry. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| try: | ||
| if handler.buffer is handler.messageBuffer: | ||
| handler.buffer.clear() | ||
| else: | ||
| handler.buffer = handler.messageBuffer | ||
|
|
||
| region = braille.TextRegion(text) | ||
| region.update() | ||
| handler.buffer.regions.append(region) | ||
| handler.buffer.update() | ||
| handler.update() | ||
| except RuntimeError: | ||
| log.debug("Braille translation failed for text, skipping braille output", exc_info=True) |
There was a problem hiding this comment.
當 handler.buffer 原本不是 handler.messageBuffer(進入 else 分支)時,handler.buffer = handler.messageBuffer 已被執行,但若隨後 region.update() 拋出 RuntimeError,handler.messageBuffer 的內容並未被清除,且 handler.buffer 已指向 messageBuffer。
雖然因為 handler.update() 從未被呼叫,所以實體點字顯示器不會立刻更新,但 handler.buffer 的指向已悄然改變。若 NVDA 內部其他機制在此之後呼叫 handler.update(),可能會將 messageBuffer 中殘留的舊內容顯示在點字機上。
建議在捕獲例外時,視情況將 handler.buffer 還原:
try:
original_buffer = handler.buffer
if handler.buffer is handler.messageBuffer:
handler.buffer.clear()
else:
handler.buffer = handler.messageBuffer
region = braille.TextRegion(text)
region.update()
handler.buffer.regions.append(region)
handler.buffer.update()
handler.update()
except RuntimeError:
handler.buffer = original_buffer # 還原緩衝區指向
log.debug("Braille translation failed for text, skipping braille output", exc_info=True)Prompt To Fix With AI
This is a comment left during a code review.
Path: addon/appModules/_utils.py
Line: 87-99
Comment:
**緩衝區狀態在例外發生後可能不一致**
當 `handler.buffer` 原本**不是** `handler.messageBuffer`(進入 `else` 分支)時,`handler.buffer = handler.messageBuffer` 已被執行,但若隨後 `region.update()` 拋出 `RuntimeError`,`handler.messageBuffer` 的內容並未被清除,且 `handler.buffer` 已指向 `messageBuffer`。
雖然因為 `handler.update()` 從未被呼叫,所以實體點字顯示器不會立刻更新,但 `handler.buffer` 的指向已悄然改變。若 NVDA 內部其他機制在此之後呼叫 `handler.update()`,可能會將 `messageBuffer` 中殘留的舊內容顯示在點字機上。
建議在捕獲例外時,視情況將 `handler.buffer` 還原:
```python
try:
original_buffer = handler.buffer
if handler.buffer is handler.messageBuffer:
handler.buffer.clear()
else:
handler.buffer = handler.messageBuffer
region = braille.TextRegion(text)
region.update()
handler.buffer.regions.append(region)
handler.buffer.update()
handler.update()
except RuntimeError:
handler.buffer = original_buffer # 還原緩衝區指向
log.debug("Braille translation failed for text, skipping braille output", exc_info=True)
```
How can I resolve this? If you propose a fix, please make it concise.| @@ -19,9 +19,9 @@ | |||
| summary = "LINE Desktop Accessibility" | |||
| description = \"\"\"Enhances NVDA accessibility support for the LINE desktop application on Windows. | |||
| Provides improved navigation for chat lists, messages, contacts, and message input.\"\"\" | |||
| author = "張可揚 <lindsay714322@gmail.com>; 洪鳳恩 <kittyhong0208@gmail.com>" | |||
| author = "張可揚 <lindsay714322@gmail.com>; 洪鳳恩 <kittyhong0208@gmail.com>; 蔡頭<tommytsaitou>" | |||
| url = None | |||
| version = 1.2.2 | |||
| version = 1.2.3beta2 | |||
| changelog = \"\"\"Initial release with LINE desktop accessibility support.\"\"\" | |||
| docFileName = readme.html | |||
| minimumNVDAVersion = 2019.3 | |||
There was a problem hiding this comment.
OUTPUT_NAME(第 13 行)使用 1.2.3-beta2(含連字號),但 manifest 中的 version(第 27 行)使用 1.2.3beta2(無連字號)。若 NVDA 根據 manifest 中的 version 欄位進行版本比對,使用者看到的檔案名稱與附加元件管理員顯示的版本號將不一致,可能造成混淆。
建議統一格式:
| version = 1.2.3-beta2 |
Prompt To Fix With AI
This is a comment left during a code review.
Path: build_addon.py
Line: 13-27
Comment:
**版本字串格式不一致**
`OUTPUT_NAME`(第 13 行)使用 `1.2.3-beta2`(含連字號),但 manifest 中的 `version`(第 27 行)使用 `1.2.3beta2`(無連字號)。若 NVDA 根據 manifest 中的 `version` 欄位進行版本比對,使用者看到的檔案名稱與附加元件管理員顯示的版本號將不一致,可能造成混淆。
建議統一格式:
```suggestion
version = 1.2.3-beta2
```
How can I resolve this? If you propose a fix, please make it concise.| description = \"\"\"Enhances NVDA accessibility support for the LINE desktop application on Windows. | ||
| Provides improved navigation for chat lists, messages, contacts, and message input.\"\"\" | ||
| author = "張可揚 <lindsay714322@gmail.com>; 洪鳳恩 <kittyhong0208@gmail.com>" | ||
| author = "張可揚 <lindsay714322@gmail.com>; 洪鳳恩 <kittyhong0208@gmail.com>; 蔡頭<tommytsaitou>" |
There was a problem hiding this comment.
蔡頭<tommytsaitou> 缺少名稱與角括號之間的空格,且 tommytsaitou 不是有效的電子郵件地址,與其他作者的格式 姓名 <email> 不符。若 NVDA 的附加元件管理員或更新機制解析此欄位,可能發生格式錯誤。
建議修正格式:
| author = "張可揚 <lindsay714322@gmail.com>; 洪鳳恩 <kittyhong0208@gmail.com>; 蔡頭<tommytsaitou>" | |
| author = "張可揚 <lindsay714322@gmail.com>; 洪鳳恩 <kittyhong0208@gmail.com>; 蔡頭 <tommytsaitou@example.com>" |
請將 tommytsaitou@example.com 替換為實際的電子郵件地址(若無正式電子郵件,可使用 GitHub 的 noreply 格式)。
Prompt To Fix With AI
This is a comment left during a code review.
Path: build_addon.py
Line: 22
Comment:
**作者欄位格式問題**
`蔡頭<tommytsaitou>` 缺少名稱與角括號之間的空格,且 `tommytsaitou` 不是有效的電子郵件地址,與其他作者的格式 `姓名 <email>` 不符。若 NVDA 的附加元件管理員或更新機制解析此欄位,可能發生格式錯誤。
建議修正格式:
```suggestion
author = "張可揚 <lindsay714322@gmail.com>; 洪鳳恩 <kittyhong0208@gmail.com>; 蔡頭 <tommytsaitou@example.com>"
```
請將 `tommytsaitou@example.com` 替換為實際的電子郵件地址(若無正式電子郵件,可使用 GitHub 的 noreply 格式)。
How can I resolve this? If you propose a fix, please make it concise.
Summary
message()function with a try-except to gracefully handleRuntimeErrorfrom liblouisTest plan
Greptile Summary
此 PR 修復了當 liblouis 無法使用
zh-tw.ctb點字表翻譯中文字元時,message()函式中點字顯示邏輯造成崩潰的問題。修復方式為在點字相關操作外層加上try-except RuntimeError,讓語音輸出不受影響,並在點字翻譯失敗時靜默跳過並記錄 debug 日誌。同時附帶版本升級至1.2.3-beta2及新增貢獻者資訊。主要變更:
addon/appModules/_utils.py:message()函式中的點字操作現在能優雅地處理RuntimeError,避免崩潰。build_addon.py:版本號從1.2.2升至1.2.3beta2,並新增作者蔡頭。OUTPUT_NAME與 manifestversion欄位的格式有些微不一致(連字號差異),以及新作者欄位格式不符合慣例(缺空格、無有效電子郵件)。Confidence Score: 4/5
此 PR 可安全合併,修復了確實存在的崩潰問題,僅有少數非關鍵的格式問題需後續處理。
核心修復邏輯正確且有針對性——捕獲 RuntimeError 是 liblouis 翻譯失敗的確切例外類型,語音輸出完全不受影響。扣一分是因為在 else 分支下存在輕微的緩衝區狀態不一致可能性,以及 build_addon.py 中版本格式與作者欄位的格式問題。
請留意 build_addon.py 中 OUTPUT_NAME 與 manifest version 欄位的格式差異,以及作者欄位格式問題。
Vulnerabilities
未發現安全問題。點字例外處理僅捕獲
RuntimeError並記錄 debug 日誌,不涉及使用者輸入驗證、憑證處理或任何敏感資料暴露。Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["message(text) 呼叫"] --> B["speech.speakMessage(text)\n語音輸出(不受影響)"] B --> C["取得 braille.handler\nassert handler"] C --> D{"handler.buffer\nis messageBuffer?"} D -->|"是(path A)"| E["handler.buffer.clear()"] D -->|"否(path B)"| F["handler.buffer = handler.messageBuffer"] E --> G["braille.TextRegion(text)"] F --> G G --> H["region.update()\n呼叫 liblouis 翻譯"] H -->|"成功"| I["buffer.regions.append(region)\nbuffer.update()\nhandler.update()"] H -->|"RuntimeError\nliblouis 翻譯失敗"| J["捕獲 RuntimeError"] J --> K["log.debug(...)\n靜默記錄,跳過點字輸出"] I --> L["點字顯示器更新完成"]Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "Fix braille crash when zh-tw.ctb cannot ..." | Re-trigger Greptile