Problem
From verification of #8/#11/#12 by devils-advocate (MEDIUM):
「testChatIdAsStringInvalidThrows 鎖了 .string("not-a-number") for chat_id throws "chat_id is required" — 但使用者有提供 chat_id,只是 type 錯了。錯誤訊息「chat_id is required」會誤導 debug — 使用者看訊息會去檢查「是不是 args 沒帶 key」,而真正的問題是「string 不是 numeric」。
與 parseMaxMessages 不對稱:
| 欄位 |
type 不對的 string |
訊息 |
max_messages |
.string("not-a-number") |
"max_messages must be an integer" ✓(清楚) |
chat_id |
.string("not-a-number") |
"chat_id is required" ✗(誤導) |
| — Source: team:devils-advocate |
|
|
Type
bug (UX)
Expected
int64ArgValue 引入第二條 throw 路徑,對「key 存在 + string 但 parse 失敗」case throw type-mismatch 而非 silently fall back to nil(之後路徑 throw "is required"):
internal func int64ArgValue(_ args: [String: Value], _ key: String) throws -> Int64? {
guard let value = args[key] else { return nil }
if let n = value.intValue { return Int64(n) }
if let s = value.stringValue {
guard let n = Int64(s) else {
throw HandlerArgError(message: "\(key) must be an integer; got \"\(s)\"")
}
return n
}
return nil
}
或:考慮統一用 SDK 的 Int64(value, strict: false) (Value.swift:354) 取代 int64ArgValue,與 #8 verify-DA 修法一致。
⚠️ Breaking change:int64ArgValue 簽名從 -> Int64? 變 throws -> Int64?。需更新 21+ callers。
Acceptance
Code Reference
Sources/CheTelegramAllMCPCore/HandlerArgs.swift:140-145 (int64ArgValue)
Tests/.../ServerHandlerLogicTests.swift (testChatIdAsStringInvalidThrows)
- 21 callers in
Sources/.../Server.swift
Related: #8, #12, #15
Problem
Type
bug (UX)
Expected
int64ArgValue引入第二條 throw 路徑,對「key 存在 + string 但 parse 失敗」case throw type-mismatch 而非 silently fall back to nil(之後路徑 throw "is required"):或:考慮統一用 SDK 的
Int64(value, strict: false)(Value.swift:354) 取代int64ArgValue,與 #8 verify-DA 修法一致。int64ArgValue簽名從-> Int64?變throws -> Int64?。需更新 21+ callers。Acceptance
.string("not-a-number")for chat_id 拋"chat_id must be an integer; got \"not-a-number\"".string("123")for chat_id 仍接受(已存在 Test: backward-compat numeric-string chat_id / from_message_id parsing #12 testChatIdAsStringAccepted)Code Reference
Sources/CheTelegramAllMCPCore/HandlerArgs.swift:140-145(int64ArgValue)Tests/.../ServerHandlerLogicTests.swift(testChatIdAsStringInvalidThrows)Sources/.../Server.swiftRelated: #8, #12, #15