jackwener/OpenCLI · error · ArgumentError
Title is ${title.length} chars — must be ≤ ${MAX_TITLE_LEN}
Error message
Title is ${title.length} chars — must be ≤ ${MAX_TITLE_LEN} What it means
ArgumentError thrown when the trimmed title exceeds MAX_TITLE_LEN (20 characters, matching XHS's title limit). The CLI validates length up front instead of letting the XHS editor truncate or reject it later.
Source
Thrown at clis/xiaohongshu/publish.js:1202
const content = String(kwargs.content ?? '').trim();
const imagePaths = kwargs.images
? String(kwargs.images).split(',').map((s) => s.trim()).filter(Boolean)
: [];
const topics = kwargs.topics
? String(kwargs.topics).split(',').map((s) => s.trim()).filter(Boolean)
: [];
const isDraft = Boolean(kwargs.draft);
const cardText = kwargs['card-text'] ? String(kwargs['card-text']) : '';
const cards = cardText
? cardText.split(CARD_TEXT_DELIM).map((s) => s.trim()).filter(Boolean)
: [];
const cardStyle = kwargs['card-style'] ? String(kwargs['card-style']).trim() : '';
const isTextImage = cards.length > 0;
// ── Validate inputs ────────────────────────────────────────────────────────
if (!title)
throw new ArgumentError('--title is required');
if (title.length > MAX_TITLE_LEN)
throw new ArgumentError(`Title is ${title.length} chars — must be ≤ ${MAX_TITLE_LEN}`);
if (!content)
throw new ArgumentError('Positional argument <content> is required');
if (!isTextImage && imagePaths.length === 0)
throw new ArgumentError('Provide --card-text (text-image mode) or --images (upload mode); neither was given.');
if (imagePaths.length > MAX_IMAGES)
throw new ArgumentError(`Too many images: ${imagePaths.length} (max ${MAX_IMAGES})`);
// The editor-page image input (text-image append) rejects gif.
if (isTextImage && imagePaths.some((p) => path.extname(p).toLowerCase() === '.gif'))
throw new ArgumentError('文字配图模式追加的图片不支持 .gif(编辑器图片入口只接受 jpg/jpeg/png/webp)');
// Validate image paths before navigating (fast-fail on bad paths / unsupported formats)
const absImagePaths = validateImagePaths(imagePaths);
// ── Step 1: Navigate to publish page ──────────────────────────────────────
await page.goto(PUBLISH_URL);
await page.wait({ time: 3 });
// Verify we landed on the creator site (not redirected to login)
const pageUrl = await page.evaluate('() => location.href');
if (!pageUrl.includes('creator.xiaohongshu.com')) {
throw new Error('Redirected away from creator center — session may have expired. ' +View on GitHub (pinned to 49907e53dc)
Solutions
- Shorten the title to ≤ 20 characters
- Move the extra text into --content (the body) instead of the title
- Count characters first (e.g. `${#title}` in bash or title.length in JS) before running
Example fix
// before --title "This is a way too long title for xiaohongshu" // after --title "短标题" // body carries the detail
Defensive patterns
Strategy: validation
Validate before calling
const title = rawTitle.trim();
if (title.length > 20) throw new Error(`Title too long: ${title.length}/20`); Type guard
function titleFits(t) {
return typeof t === 'string' && t.trim().length > 0 && t.trim().length <= 20;
} Try / catch
try {
await publish(page, { title, ...rest });
} catch (e) {
if (String(e.message).includes('must be ≤')) {
title = title.slice(0, 20);
// retry with truncated title
} else throw e;
} Prevention
- Keep titles ≤ 20 characters — XHS counts every char including spaces
- Put long text in --content, not the title
- Validate length in scripts before invoking the CLI
When it happens
Trigger: Running the publish command where `title.length > 20` after trimming — e.g. --title with a long sentence or non-CJK text that quickly exceeds 20 chars.
Common situations: English/long titles easily exceed 20 characters even when they feel short; pasting a full headline intended for the body into --title; not realizing XHS counts characters (including spaces/punctuation) toward the 20-char cap.
Related errors
- --title is required
- Positional argument <content> is required
- Provide --card-text (text-image mode) or --images (upload mo
- Too many images: ${imagePaths.length} (max ${MAX_IMAGES})
- INVALID_ARGUMENT
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/9893ae5d9c2cfab8.
Report an issue: GitHub.