jackwener/OpenCLI · error · ArgumentError

Positional argument <content> is required

Error message

Positional argument <content> is required

What it means

ArgumentError thrown when the trimmed positional <content> argument is empty. Every publish (text-image or upload mode) requires body content, so the CLI fails fast before any browser automation runs.

Source

Thrown at clis/xiaohongshu/publish.js:1204

            ? 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. ' +
                'Re-capture browser login via: opencli xiaohongshu creator-profile');
        }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass the body text as the positional argument: publish.js --title "标题" "正文内容"
  2. Quote multi-word content so the shell passes it as one argument
  3. Verify the content is not only whitespace after trimming

Example fix

// before
node publish.js --title "标题" --card-text "a|b"   # content missing
// after
node publish.js --title "标题" --card-text "a|b" "这是正文内容"
Defensive patterns

Strategy: validation

Validate before calling

const content = String(rawContent ?? '').trim();
if (!content) throw new Error('Positional <content> is required');

Type guard

function hasContent(c) {
  return typeof c === 'string' && c.trim().length > 0;
}

Try / catch

try {
  await publish(page, { title, content, ...rest });
} catch (e) {
  if (String(e.message).includes('<content> is required')) {
    console.error('Pass body text as the positional argument, quoted');
  }
  throw e;
}

Prevention

When it happens

Trigger: Running the publish command without the positional content argument, or with an empty/whitespace-only string, so `String(kwargs.content ?? '').trim()` is empty.

Common situations: Forgetting the positional argument entirely; quoting mistakes so the shell swallows the content; passing content via a flag by mistake instead of positionally; content consisting only of whitespace/newlines.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/64a7fa0e4e383bb6. Report an issue: GitHub.