xpzouying/xiaohongshu-mcp · error

当前输入长度为%s,最大长度为%s

Error message

当前输入长度为%s,最大长度为%s

What it means

This is the successfully-parsed over-length error from makeMaxLengthError: the page showed a title or content length-error indicator, its text matched the 'current/max' pattern, and the library reports the current input length versus the maximum allowed. It means the user's content or title exceeds Xiaohongshu's character limit and the publish cannot proceed.

Source

Thrown at xiaohongshu/publish.go:643

	}

	contentLength, err := elem.Text()
	if err != nil {
		return errors.Wrap(err, "获取正文长度文本失败")
	}

	return makeMaxLengthError(contentLength)
}

func makeMaxLengthError(elemText string) error {
	parts := strings.Split(elemText, "/")
	if len(parts) != 2 {
		return errors.Errorf("长度超过限制: %s", elemText)
	}

	currLen, maxLen := parts[0], parts[1]

	return errors.Errorf("当前输入长度为%s,最大长度为%s", currLen, maxLen)
}

// contentElemSelectors 正文输入框的候选选择器,按先后顺序尝试。
var contentElemSelectors = []string{
	`div[role="textbox"][contenteditable="true"]`,
	`div.tiptap[contenteditable="true"]`,
	`div.ql-editor`,
}

// getContentElement 在 timeout 内轮询查找正文输入框,全部落空返回错误。
func getContentElement(page *rod.Page, timeout time.Duration) (*rod.Element, error) {
	deadline := time.Now().Add(timeout)

	for {
		elem, err := findContentElement(page)
		if err == nil {
			return elem, nil
		}

View on GitHub (pinned to 332d196854)

Solutions

  1. Truncate the content to the reported max length before calling the publish API (the error tells you currLen and maxLen).
  2. Shorten the title to fit the title limit.
  3. Validate text length in your own code pre-publish (count runes the same way the site does).
  4. If content is legitimately within limits but the badge appears, check for hidden characters or trailing whitespace.

Example fix

// before
err := publisher.Publish(ctx, opts) // fails with 当前输入长度为1002,最大长度为1000
// after
if utf8.RuneCountInString(opts.Content) > 1000 {
    opts.Content = string([]rune(opts.Content)[:1000])
}
err := publisher.Publish(ctx, opts)
Defensive patterns

Strategy: validation

Validate before calling

// enforce limits before calling the library
const maxTitle, maxContent = 20, 1000
if utf8.RuneCountInString(title) > maxTitle {
    return fmt.Errorf("标题超长: %d/%d", utf8.RuneCountInString(title), maxTitle)
}
if utf8.RuneCountInString(content) > maxContent {
    return fmt.Errorf("正文超长: %d/%d", utf8.RuneCountInString(content), maxContent)
}

Type guard

func withinLimit(s string, max int) bool {
    return utf8.RuneCountInString(s) <= max
}

Try / catch

err := publisher.Publish(ctx, opts)
var lenErr interface{ Error() string }
if err != nil && strings.Contains(err.Error(), "当前输入长度为") {
    // parse '当前输入长度为X,最大长度为Y' and truncate before retrying
    return truncateAndRetry(opts, err.Error())
}

Prevention

When it happens

Trigger: submitPublish calls checkTitleMaxLength / checkContentMaxLength after filling fields; the page displays the over-length badge (div.title-container div.max_suffix or div.edit-container div.length-error) whose text parses as '<currLen>/<maxLen>', producing this formatted error.

Common situations: Pasting long articles into the body editor; titles over ~20 characters; content with many emoji or multi-byte characters counted differently than expected; programmatically generated content exceeding the cap.

Related errors


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