{"record":{"id":"cdb200ccff1847fb","repo":"chenhg5/cc-connect","slug":"tuitui-invalid-chat-type-q","errorCode":null,"errorMessage":"tuitui: invalid chat type %q","messagePattern":"tuitui: invalid chat type %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/tuitui/history.go","lineNumber":45,"sourceCode":"\tMessages    []map[string]any `json:\"msgs,omitempty\"`\n\tThreads     []string         `json:\"threads,omitempty\"`\n}\n\nfunc (p *Platform) FetchHistory(ctx context.Context, chatID, chatType string, opts HistoryOptions) (*HistoryResult, error) {\n\tchatID = strings.TrimSpace(chatID)\n\tif chatID == \"\" {\n\t\treturn nil, fmt.Errorf(\"tuitui: chat id is required\")\n\t}\n\tif chatType == \"\" {\n\t\tchatType = guessChatType(chatID)\n\t}\n\tswitch chatType {\n\tcase chatTypeDirect, chatTypeGroup:\n\t\treturn p.fetchDirectOrGroupHistory(ctx, chatID, chatType, opts)\n\tcase chatTypeChannel:\n\t\treturn p.fetchChannelHistory(ctx, chatID, opts)\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"tuitui: invalid chat type %q\", chatType)\n\t}\n}\n\nfunc (p *Platform) fetchDirectOrGroupHistory(ctx context.Context, chatID, chatType string, opts HistoryOptions) (*HistoryResult, error) {\n\tpayload := map[string]any{\"cursor\": \"0\"}\n\tif chatType == chatTypeDirect {\n\t\tpayload[\"user\"] = chatID\n\t} else {\n\t\tpayload[\"group_id\"] = chatID\n\t}\n\taddHistoryOptions(payload, opts)\n\n\tapiPath := \"/robot/message/group/sync\"\n\tif chatType == chatTypeDirect {\n\t\tapiPath = \"/robot/message/single/sync\"\n\t}\n\tvar out struct {\n\t\tErrCode int              `json:\"errcode\"`","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/tuitui/history.go#L27-L63","documentation":"FetchHistory was called with a chatType other than the supported \"direct\", \"group\", or \"channel\". TuiTui dispatches history fetching to different endpoints per chat type; any unrecognized type is rejected. Note that an empty chatType is auto-guessed from the ID format, so this error only fires for explicitly wrong non-empty values.","triggerScenarios":"Calling FetchHistory(ctx, id, \"chat\", opts) or any misspelled type; passing a type constant from another platform (e.g. \"private\", \"dm\", \"channel_post\"); user-configured chat type with a typo.","commonSituations":"Copied code from another platform adapter using its chat-type vocabulary; config file mapping chats with the wrong type labels; refactor renamed constants but a call site was missed.","solutions":["Use one of the supported values: direct, group, or channel (case as expected by the switch).","Omit chatType and let guessChatType infer it from the chat ID format.","Log/inspect the actual chatType value received — it is quoted in the error.","Normalize input with strings.ToLower(strings.TrimSpace(chatType)) before calling."],"exampleFix":"// before\np.FetchHistory(ctx, chatID, \"private\", opts)\n// after\np.FetchHistory(ctx, chatID, \"direct\", opts) // or \"\" to auto-guess","handlingStrategy":"validation","validationCode":"var validChatTypes = map[string]bool{\"direct\": true, \"group\": true, \"channel\": true}\nif !validChatTypes[strings.ToLower(strings.TrimSpace(chatType))] {\n    chatType = \"\" // let guessChatType infer\n}","typeGuard":"func isKnownChatType(t string) bool {\n    switch strings.ToLower(strings.TrimSpace(t)) {\n    case \"direct\", \"group\", \"channel\": return true\n    }\n    return false\n}","tryCatchPattern":"res, err := p.FetchHistory(ctx, chatID, chatType, opts)\nif err != nil {\n    var inv *invalidChatTypeError\n    if errors.As(err, &inv) { chatType = \"\"; res, err = p.FetchHistory(ctx, chatID, \"\", opts) }\n}","preventionTips":["Define shared string constants for chat types instead of inline literals","Omit chatType when unsure — it is inferred from the ID format","Normalize case/whitespace before passing","Keep a mapping table if porting from another platform's vocabulary"],"tags":["tuitui","validation","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}