xpzouying/xiaohongshu-mcp · warning
回复内容不能为空
Error message
回复内容不能为空
What it means
Reply validates its inputs before opening the browser and fails fast when the reply body is empty or whitespace-only. Xiaohongshu rejects empty replies, so the library checks strings.TrimSpace(content) and returns this error to avoid a wasted page navigation. It is thrown before any network or browser interaction.
Source
Thrown at xiaohongshu/notification_reply.go:28
"github.com/sirupsen/logrus"
"github.com/xpzouying/xiaohongshu-mcp/humanize"
)
// NotificationReplyResult 通知回复的结果。
type NotificationReplyResult struct {
CommentID string `json:"comment_id"`
Nickname string `json:"nickname"`
FeedID string `json:"feed_id,omitempty"`
Content string `json:"content"`
}
// Reply 回复一条评论。
func (n *NotificationAction) Reply(ctx context.Context, commentID, content string) (*NotificationReplyResult, error) {
if strings.TrimSpace(commentID) == "" {
return nil, fmt.Errorf("缺少 comment_id")
}
if strings.TrimSpace(content) == "" {
return nil, fmt.Errorf("回复内容不能为空")
}
page := n.page.Timeout(3 * time.Minute)
page.MustNavigate("https://www.xiaohongshu.com/notification").MustWaitLoad()
humanize.Delay(ctx, humanize.AfterNavigate)
target, index, err := n.locate(ctx, page, commentID)
if err != nil {
return nil, err
}
items, err := page.Elements(`.tabs-content-container > .container`)
if err != nil {
return nil, fmt.Errorf("未找到通知条目: %w", err)
}
if index >= len(items) {
return nil, fmt.Errorf("通知条目渲染数(%d)少于目标位置(%d),页面可能未加载完", len(items), index)View on GitHub (pinned to 332d196854)
Solutions
- Pass a non-empty, trimmed reply string to Reply
- Validate content at the call site before invoking Reply
- Log the content variable upstream to find where it became empty
Example fix
// before
content := tpl.Execute(data)
reply, err := n.Reply(ctx, commentID, content)
// after
content := strings.TrimSpace(tpl.Execute(data))
if content == "" {
return fmt.Errorf("reply template produced empty content")
}
reply, err := n.Reply(ctx, commentID, content) Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(commentID) == "" || strings.TrimSpace(content) == "" {
return fmt.Errorf("commentID and content must be non-empty")
} Try / catch
res, err := n.Reply(ctx, commentID, content)
if err != nil && strings.Contains(err.Error(), "回复内容不能为空") {
// fix input upstream, do not retry
} Prevention
- Trim and check content before every Reply call
- Validate LLM/template output is non-empty before passing it in
- Fail fast at the call site with a clear message
When it happens
Trigger: Calling NotificationAction.Reply(ctx, commentID, "") or with content consisting only of spaces/tabs/newlines (e.g. a variable that failed to populate upstream).
Common situations: Template/LLM-generated reply text came back empty; config or DB lookup returned blank string; caller trimmed content and passed the result accidentally.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/5b07663f9f6c686e.
Report an issue: GitHub.