fix: PyPtt.ParameterError 標成 PARAMETER_ERROR,不再誤標 UNKNOWN_ERROR - #23
Merged
Conversation
_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>
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.
問題
utils._handle_ptt_exception的EXCEPTION_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.py:ParameterError → PARAMETER_ERROR(含原訊息)、其他例外仍走UNKNOWN_ERROR。已驗 fail-before / pass-after。flake8 ./mypy .全樹綠(= CI 內容)、pytest19 passed。🤖 Generated with Claude Code