xpzouying/xiaohongshu-mcp · error
%s后无法确认状态: %w
Error message
%s后无法确认状态: %w
What it means
After clicking, toggleInteract polls the note's state for up to 4s to confirm the liked/collected flag became the desired value. If state can't be read at all it throws '<actionType>后无法确认状态: %w'; if it reads but never matches after 2 clicks it reports a mismatch — eliminating false-positive successes.
Source
Thrown at xiaohongshu/like_favorite.go:79
return fmt.Errorf("未找到交互元素 %s: %w", selector, err)
}
return humanize.Click(element)
}
// stateOf 从交互状态里取目标字段(点赞取 liked,收藏取 collected)。
type stateOf func(liked, collected bool) bool
// toggleInteract 点击交互按钮并轮询校验状态是否变为 want;最多两次点击。
// 到达即成功;始终未变或无法读状态则返回 error——消除"点了没报错就算成功"的假阳性。
func (a *interactAction) toggleInteract(ctx context.Context, page *rod.Page, feedID, selector string, want bool, actionType interactActionType, pick stateOf) error {
for attempt := 1; attempt <= 2; attempt++ {
if err := a.performClick(page, selector); err != nil {
return fmt.Errorf("%s点击失败: %w", actionType, err)
}
ok, err := a.waitInteractState(page, feedID, want, pick, 4*time.Second)
if err != nil {
return fmt.Errorf("%s后无法确认状态: %w", actionType, err)
}
if ok {
humanize.Delay(ctx, humanize.AfterInteract)
logrus.Infof("feed %s %s成功(第%d次点击)", feedID, actionType, attempt)
return nil
}
logrus.Warnf("feed %s %s第%d次点击后状态未变,重试", feedID, actionType, attempt)
}
return fmt.Errorf("feed %s %s失败:点击后状态始终未变为预期", feedID, actionType)
}
// waitInteractState 轮询 __INITIAL_STATE__ 的交互状态,直到 pick()==want 或超时。
// 状态回写快则立即返回、慢则等满 timeout。
func (a *interactAction) waitInteractState(page *rod.Page, feedID string, want bool, pick stateOf, timeout time.Duration) (bool, error) {
deadline := time.Now().Add(timeout)
for {
liked, collected, err := a.getInteractState(page, feedID)
if err != nil {View on GitHub (pinned to 332d196854)
Solutions
- Unwrap the cause to distinguish read-failure vs state-never-changed
- Verify the account session is valid (an expired session swallows clicks)
- Increase the poll timeout or retries for slow networks; update state-reading code if schema changed
Defensive patterns
Strategy: try-catch
Try / catch
err := client.LikeFeed(ctx, feedID)
if err != nil && strings.Contains(err.Error(), "无法确认状态") {
// verify manually before assuming success or retrying
log.Warnf("state unverified for %s: %v", feedID, err)
return err
} Prevention
- Keep sessions valid — expired sessions silently ignore clicks
- Allow longer settle time on slow networks before state polling gives up
- Treat this error as 'unverified', never as success
When it happens
Trigger: Click succeeded but the initial-state polling couldn't read the liked/collected field (state JSON shape changed, extraction failed) within the 4s window on both attempts.
Common situations: Rate limiting or login expiry causing server to ignore the click; __INITIAL_STATE__ schema change breaking the state reader; very slow network exceeding the 4s poll.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/58d264660f83da32.
Report an issue: GitHub.