Skip to content

fix: PyPtt.ParameterError 標成 PARAMETER_ERROR,不再誤標 UNKNOWN_ERROR - #23

Merged
PttCodingMan merged 1 commit into
mainfrom
fix/parameter-error-code
Jul 20, 2026
Merged

fix: PyPtt.ParameterError 標成 PARAMETER_ERROR,不再誤標 UNKNOWN_ERROR#23
PttCodingMan merged 1 commit into
mainfrom
fix/parameter-error-code

Conversation

@PttCodingMan

Copy link
Copy Markdown
Member

問題

utils._handle_ptt_exceptionEXCEPTION_MAPPING 沒收錄 PyPtt.ParameterError,所以參數類錯誤會落到最後的 fallback、被貼成 UNKNOWN_ERROR「操作時發生未知錯誤」——訊息其實有帶到,但 code 誤導。

最典型:del_post(bad_post_type="OTHER") 沒給 bad_post_reason(PyPtt 丟 ParameterError)。

修法

在 fallback 前加一條 ParameterError 專屬處理,回 PARAMETER_ERROR 並保留 PyPtt 原始訊息。所有工具的參數錯誤都受惠,不只 del_post;不重複 PyPtt 的驗證邏輯。

測試

  • 新增 src/test_utils.pyParameterError → PARAMETER_ERROR(含原訊息)、其他例外仍走 UNKNOWN_ERROR。已驗 fail-before / pass-after。
  • flake8 . / mypy . 全樹綠(= CI 內容)、pytest 19 passed。

🤖 Generated with Claude Code

_handle_ptt_exception 沒收錄 ParameterError,導致參數錯誤(如 del_post bad_post_type=OTHER 卻沒給 reason、reason 超長)被貼成 UNKNOWN_ERROR「操作時發生未知錯誤」,code 誤導。改為專屬 PARAMETER_ERROR 並保留 PyPtt 原始訊息,所有工具的參數錯誤都受惠。新增 src/test_utils.py 驗此對應(含真 PyPtt 的 sys.modules 隔離)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@PttCodingMan
PttCodingMan merged commit b29f003 into main Jul 20, 2026
1 check passed
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