xpzouying/xiaohongshu-mcp · error

未知的主页 tab %q,可选:note / fav / liked

Error message

未知的主页 tab %q,可选:note / fav / liked

What it means

ParseProfileTab 的枚举校验守卫:trim+lower 后的输入不匹配 note/fav/liked 及其别名的任何一个(空串合法默认 note)。调用方传了非法的 tab 名,属参数错误。

Source

Thrown at xiaohongshu/user_profile.go:33

type ProfileTab string

const (
	TabNotes     ProfileTab = "note"
	TabFavorites ProfileTab = "fav"
	TabLiked     ProfileTab = "liked"
)

// ParseProfileTab 解析 tab 名,空值默认为「笔记」。
func ParseProfileTab(s string) (ProfileTab, error) {
	switch strings.TrimSpace(strings.ToLower(s)) {
	case "", "note", "notes", "笔记":
		return TabNotes, nil
	case "fav", "favorites", "favorite", "收藏":
		return TabFavorites, nil
	case "liked", "like", "点赞":
		return TabLiked, nil
	}
	return "", fmt.Errorf("未知的主页 tab %q,可选:note / fav / liked", s)
}

// tabLabel 子 tab 对应的页面文字。
var tabLabel = map[ProfileTab]string{
	TabNotes:     "笔记",
	TabFavorites: "收藏",
	TabLiked:     "点赞",
}

type UserProfileAction struct {
	page *rod.Page
}

func NewUserProfileAction(page *rod.Page) *UserProfileAction {
	pp := page.Timeout(60 * time.Second)
	return &UserProfileAction{page: pp}
}

View on GitHub (pinned to 332d196854)

Solutions

  1. 改用白名单内的值:note / fav / liked(或其别名:收藏、点赞等)
  2. 调用前先做规范化:小写、去空格
  3. 不确定时先传空字符串,库会默认按 TabNotes 处理

Example fix

// before
tab, err := xiaohongshu.ParseProfileTab("Notes") // 大小写不符
// after
tab, err := xiaohongshu.ParseProfileTab(strings.ToLower(strings.TrimSpace("Notes")))
if tab == "" { tab = xiaohongshu.TabNotes }
Defensive patterns

Strategy: validation

Validate before calling

var validTabs = []string{"note","fav","favorites","favorite","收藏","liked","like","点赞"}
s := strings.ToLower(strings.TrimSpace(tab))
if !contains(validTabs, s) {
  return fmt.Errorf("tab %q 非法,可选 note / fav / liked", tab)
}

Type guard

func isValidProfileTab(s string) bool {
  switch s {
  case "note", "fav", "favorites", "favorite", "收藏", "liked", "like", "点赞":
    return true
  }
  return false
}

Try / catch

tab, err := xiaohongshu.ParseProfileTab(input)
if err != nil {
    log.Printf("非法 tab %q,回退默认 note", input)
    tab = xiaohongshu.TabNotes
}

Prevention

When it happens

Trigger: 调用 UserProfile / GetMyProfile 并传入 tab 字符串,如 "notes"(复数不识别?取决于白名单)、"likes"、"收藏夹"、"video" 等不在白名单中的值;测试 TestParseProfileTab 传入非法值。

Common situations: 调用方误用复数形式("notes"/"likes");大小写不匹配("Note");传了中文别名之外的中文词;直接把前端路由的 tab 名照搬过来。

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05). Data as JSON: /api/errors/2733b94a9574e63e. Report an issue: GitHub.