{"record":{"id":"4d015a651ed53633","repo":"chenhg5/cc-connect","slug":"tuitui-channel-history-errcode-d-errmsg-s","errorCode":null,"errorMessage":"tuitui: channel history errcode=%d errmsg=%s","messagePattern":"tuitui: channel history errcode=(.+?) errmsg=(.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/tuitui/history.go","lineNumber":168,"sourceCode":"\t\t\t} else {\n\t\t\t\tpayload[\"from_timestamp\"] = opts.Cursor\n\t\t\t}\n\t\t}\n\t}\n\n\tvar out struct {\n\t\tErrCode int    `json:\"errcode\"`\n\t\tErrMsg  string `json:\"errmsg\"`\n\t\tTime    any    `json:\"time\"`\n\t\tDatas   struct {\n\t\t\tPostList []map[string]any `json:\"post_list\"`\n\t\t} `json:\"datas\"`\n\t}\n\tif err := p.postJSON(ctx, \"/robot/teams/post/topic/list\", payload, &out); err != nil {\n\t\treturn nil, err\n\t}\n\tif out.ErrCode != 0 {\n\t\treturn nil, fmt.Errorf(\"tuitui: channel history errcode=%d errmsg=%s\", out.ErrCode, out.ErrMsg)\n\t}\n\tcursor := \"\"\n\tif len(out.Datas.PostList) > 0 {\n\t\tif topic, _ := out.Datas.PostList[len(out.Datas.PostList)-1][\"topic\"].(map[string]any); topic != nil {\n\t\t\tif n := numberFromAny(topic[\"last_reply_time\"]); n > 0 {\n\t\t\t\tnext := int64(n) + 1\n\t\t\t\tif order == \"desc\" {\n\t\t\t\t\tnext = int64(n) - 1\n\t\t\t\t}\n\t\t\t\tcursor = strconv.FormatInt(next, 10)\n\t\t\t}\n\t\t}\n\t}\n\treturn &HistoryResult{\n\t\tErrCode:     out.ErrCode,\n\t\tErrMsg:      out.ErrMsg,\n\t\tCursor:      cursor,\n\t\tHasMore:     len(out.Datas.PostList) >= limit,","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/tuitui/history.go#L150-L186","documentation":"The TuiTui channel topic/post list API (/robot/teams/post/topic/list) returned a non-zero errcode, meaning the backend rejected the history query despite an HTTP-level success. The backend errmsg is surfaced verbatim so the specific cause can be diagnosed.","triggerScenarios":"fetchChannelHistory posts the topic list request and out.ErrCode != 0 — e.g. invalid team_id, bot lacking team permissions, channel archived/deleted, or pagination cursor past the end.","commonSituations":"Bot not added to the team; team_id derived from a stale channel-info cache; requesting history in a channel whose posts were purged; backend limit/permission changes on the TuiTui side.","solutions":["Inspect errmsg for the backend's stated reason and match it to the errcode docs.","Re-fetch channel info to get a fresh team_id, then retry.","Verify bot membership and permissions on the target team.","If transient (backend 5xx-style errcode), retry with backoff."],"exampleFix":"// before\nif out.ErrCode != 0 {\n    return nil, fmt.Errorf(\"tuitui: channel history errcode=%d errmsg=%s\", out.ErrCode, out.ErrMsg)\n}\n// after\nif out.ErrCode != 0 {\n    if isTransient(out.ErrCode) { return p.fetchChannelHistory(ctx, chatID, opts) }\n    return nil, fmt.Errorf(\"tuitui: channel history errcode=%d errmsg=%s\", out.ErrCode, out.ErrMsg)\n}","handlingStrategy":"retry","validationCode":"if _, err := p.getChannelInfo(ctx, channelID); err != nil {\n    return fmt.Errorf(\"channel unavailable for history: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"res, err := p.FetchHistory(ctx, channelID, \"channel\", opts)\nif err != nil {\n    if retriable(err) { // transient backend errcode\n        backoff(ctx, func() error { res, err = p.FetchHistory(ctx, channelID, \"channel\", opts); return err })\n    }\n}","preventionTips":["Verify bot team membership and permissions first","Refresh team_id from channel info rather than caching indefinitely","Treat not-found vs permission errcodes differently (no retry vs fix access)","Cap retries with backoff to avoid hammering a failing backend"],"tags":["tuitui","api","channel"],"backgroundTag":"api-error-response","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"}