Skip to content

chat_id type-mismatch error message misleads (silently shows 'is required' instead of type error) #22

@kiki830621

Description

@kiki830621

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 changeint64ArgValue 簽名從 -> 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions