{"record":{"id":"2733b94a9574e63e","repo":"xpzouying/xiaohongshu-mcp","slug":"tab-q-note-fav-liked","errorCode":null,"errorMessage":"未知的主页 tab %q，可选：note / fav / liked","messagePattern":"未知的主页 tab %q，可选：note / fav / liked","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/user_profile.go","lineNumber":33,"sourceCode":"type ProfileTab string\n\nconst (\n\tTabNotes     ProfileTab = \"note\"\n\tTabFavorites ProfileTab = \"fav\"\n\tTabLiked     ProfileTab = \"liked\"\n)\n\n// ParseProfileTab 解析 tab 名，空值默认为「笔记」。\nfunc ParseProfileTab(s string) (ProfileTab, error) {\n\tswitch strings.TrimSpace(strings.ToLower(s)) {\n\tcase \"\", \"note\", \"notes\", \"笔记\":\n\t\treturn TabNotes, nil\n\tcase \"fav\", \"favorites\", \"favorite\", \"收藏\":\n\t\treturn TabFavorites, nil\n\tcase \"liked\", \"like\", \"点赞\":\n\t\treturn TabLiked, nil\n\t}\n\treturn \"\", fmt.Errorf(\"未知的主页 tab %q，可选：note / fav / liked\", s)\n}\n\n// tabLabel 子 tab 对应的页面文字。\nvar tabLabel = map[ProfileTab]string{\n\tTabNotes:     \"笔记\",\n\tTabFavorites: \"收藏\",\n\tTabLiked:     \"点赞\",\n}\n\ntype UserProfileAction struct {\n\tpage *rod.Page\n}\n\nfunc NewUserProfileAction(page *rod.Page) *UserProfileAction {\n\tpp := page.Timeout(60 * time.Second)\n\treturn &UserProfileAction{page: pp}\n}\n","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/user_profile.go#L15-L51","documentation":"ParseProfileTab 的枚举校验守卫：trim+lower 后的输入不匹配 note/fav/liked 及其别名的任何一个（空串合法默认 note）。调用方传了非法的 tab 名，属参数错误。","triggerScenarios":"调用 UserProfile / GetMyProfile 并传入 tab 字符串，如 \"notes\"（复数不识别？取决于白名单）、\"likes\"、\"收藏夹\"、\"video\" 等不在白名单中的值；测试 TestParseProfileTab 传入非法值。","commonSituations":"调用方误用复数形式（\"notes\"/\"likes\"）；大小写不匹配（\"Note\"）；传了中文别名之外的中文词；直接把前端路由的 tab 名照搬过来。","solutions":["改用白名单内的值：note / fav / liked（或其别名：收藏、点赞等）","调用前先做规范化：小写、去空格","不确定时先传空字符串，库会默认按 TabNotes 处理"],"exampleFix":"// before\ntab, err := xiaohongshu.ParseProfileTab(\"Notes\") // 大小写不符\n// after\ntab, err := xiaohongshu.ParseProfileTab(strings.ToLower(strings.TrimSpace(\"Notes\")))\nif tab == \"\" { tab = xiaohongshu.TabNotes }","handlingStrategy":"validation","validationCode":"var validTabs = []string{\"note\",\"fav\",\"favorites\",\"favorite\",\"收藏\",\"liked\",\"like\",\"点赞\"}\ns := strings.ToLower(strings.TrimSpace(tab))\nif !contains(validTabs, s) {\n  return fmt.Errorf(\"tab %q 非法，可选 note / fav / liked\", tab)\n}","typeGuard":"func isValidProfileTab(s string) bool {\n  switch s {\n  case \"note\", \"fav\", \"favorites\", \"favorite\", \"收藏\", \"liked\", \"like\", \"点赞\":\n    return true\n  }\n  return false\n}","tryCatchPattern":"tab, err := xiaohongshu.ParseProfileTab(input)\nif err != nil {\n    log.Printf(\"非法 tab %q，回退默认 note\", input)\n    tab = xiaohongshu.TabNotes\n}","preventionTips":["传参前统一 ToLower + TrimSpace","使用 TabNotes/TabFavorites/TabLiked 常量而非字符串","避免复数形式 \"notes\"/\"likes\"","把空字符串视为合法（默认 TabNotes）"],"tags":["validation","invalid-argument","user-profile"],"backgroundTag":"invalid-enum-value","analyzedSha":"332d196854a9eac0d2b8c2c0e3d0cc43139d724c","analyzedAt":"2026-09-05T22:22:55.988Z","contentChangedAt":"2026-09-05T22:22:55.988Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}