Skip to content

Fix braille crash when zh-tw.ctb cannot translate Chinese text#50

Merged
keyang556 merged 3 commits intomainfrom
claude/hopeful-northcutt
Apr 9, 2026
Merged

Fix braille crash when zh-tw.ctb cannot translate Chinese text#50
keyang556 merged 3 commits intomainfrom
claude/hopeful-northcutt

Conversation

@keyang556
Copy link
Copy Markdown
Owner

@keyang556 keyang556 commented Apr 9, 2026

Summary

  • Wraps braille display calls in the message() function with a try-except to gracefully handle RuntimeError from liblouis
  • Fixes crashes when liblouis fails to translate Chinese characters with the zh-tw.ctb table
  • Speech output is unaffected; braille output is silently skipped with a debug log entry

Test plan

  • Verify that the "more options" menu (NVDA+Windows+O) works without crashing
  • Check NVDA logs to confirm debug message appears when braille translation fails

Greptile Summary

此 PR 修復了當 liblouis 無法使用 zh-tw.ctb 點字表翻譯中文字元時,message() 函式中點字顯示邏輯造成崩潰的問題。修復方式為在點字相關操作外層加上 try-except RuntimeError,讓語音輸出不受影響,並在點字翻譯失敗時靜默跳過並記錄 debug 日誌。同時附帶版本升級至 1.2.3-beta2 及新增貢獻者資訊。

主要變更:

  • addon/appModules/_utils.pymessage() 函式中的點字操作現在能優雅地處理 RuntimeError,避免崩潰。
  • build_addon.py:版本號從 1.2.2 升至 1.2.3beta2,並新增作者 蔡頭
  • 需注意:OUTPUT_NAME 與 manifest version 欄位的格式有些微不一致(連字號差異),以及新作者欄位格式不符合慣例(缺空格、無有效電子郵件)。

Confidence Score: 4/5

此 PR 可安全合併,修復了確實存在的崩潰問題,僅有少數非關鍵的格式問題需後續處理。

核心修復邏輯正確且有針對性——捕獲 RuntimeError 是 liblouis 翻譯失敗的確切例外類型,語音輸出完全不受影響。扣一分是因為在 else 分支下存在輕微的緩衝區狀態不一致可能性,以及 build_addon.py 中版本格式與作者欄位的格式問題。

請留意 build_addon.py 中 OUTPUT_NAME 與 manifest version 欄位的格式差異,以及作者欄位格式問題。

Vulnerabilities

未發現安全問題。點字例外處理僅捕獲 RuntimeError 並記錄 debug 日誌,不涉及使用者輸入驗證、憑證處理或任何敏感資料暴露。

Important Files Changed

Filename Overview
addon/appModules/_utils.py 將點字顯示呼叫包裹於 try-except(RuntimeError) 中,防止 liblouis 無法翻譯中文字元時造成崩潰;但在 else 分支修改 handler.buffer 後發生例外時,緩衝區指向可能殘留不一致狀態。
build_addon.py 版本號從 1.2.2 升至 1.2.3-beta2 並新增作者,但 OUTPUT_NAME 與 manifest version 格式不一致(連字號差異),且新增作者欄位缺少空格且無有效電子郵件。

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["點字顯示器更新完成"]
Loading

Fix All in Claude Code Fix All in Codex

Prompt To Fix All 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.

---

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.

---

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.

Reviews (1): Last reviewed commit: "Fix braille crash when zh-tw.ctb cannot ..." | Re-trigger Greptile

Greptile also left 3 inline comments on this PR.

keyang556 and others added 3 commits April 9, 2026 12:51
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>
Comment on lines +87 to +99
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 緩衝區狀態在例外發生後可能不一致

handler.buffer 原本不是 handler.messageBuffer(進入 else 分支)時,handler.buffer = handler.messageBuffer 已被執行,但若隨後 region.update() 拋出 RuntimeErrorhandler.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.

Fix in Claude Code Fix in Codex

Comment on lines 13 to 27
@@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 版本字串格式不一致

OUTPUT_NAME(第 13 行)使用 1.2.3-beta2(含連字號),但 manifest 中的 version(第 27 行)使用 1.2.3beta2(無連字號)。若 NVDA 根據 manifest 中的 version 欄位進行版本比對,使用者看到的檔案名稱與附加元件管理員顯示的版本號將不一致,可能造成混淆。

建議統一格式:

Suggested change
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.

Fix in Claude Code Fix in Codex

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>"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 作者欄位格式問題

蔡頭<tommytsaitou> 缺少名稱與角括號之間的空格,且 tommytsaitou 不是有效的電子郵件地址,與其他作者的格式 姓名 <email> 不符。若 NVDA 的附加元件管理員或更新機制解析此欄位,可能發生格式錯誤。

建議修正格式:

Suggested change
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.

Fix in Claude Code Fix in Codex

@keyang556 keyang556 merged commit 004522f into main Apr 9, 2026
2 of 3 checks passed
@keyang556 keyang556 deleted the claude/hopeful-northcutt branch April 9, 2026 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant