jackwener/OpenCLI · error · ArgumentError

--title is required

Error message

--title is required

What it means

ArgumentError thrown during input validation when the trimmed --title value is empty. The publish command requires a non-empty title string; an empty title would fail on the XHS editor anyway, so the CLI fails fast before navigating to the publish page.

Source

Thrown at clis/xiaohongshu/publish.js:1200

            throw new Error('Browser page required');
        const title = String(kwargs.title ?? '').trim();
        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');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a non-empty --title "你的标题" argument
  2. Check shell variable expansion — echo the value before running to confirm it is not empty
  3. Remember the title must also be ≤ 20 chars (MAX_TITLE_LEN) to pass the next check

Example fix

// before
node publish.js --title "" --content "正文"
// after
node publish.js --title "我的笔记标题" --content "正文"
Defensive patterns

Strategy: validation

Validate before calling

const title = String(process.argvTitle ?? '').trim();
if (!title) throw new Error('--title is required');

Type guard

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

Try / catch

try {
  await publish(page, { title, ...rest });
} catch (e) {
  if (e.name === 'ArgumentError' && e.message.includes('--title')) {
    console.error('Supply a non-empty --title, e.g. --title "我的标题"');
  }
  throw e;
}

Prevention

When it happens

Trigger: Running the publish command with no --title flag, with --title "" or --title " " (whitespace only), so `String(kwargs.title ?? '').trim()` yields an empty string.

Common situations: Forgetting the --title flag; shell quoting issues that drop the value (e.g. --title "$UNSET_VAR"); passing the title positionally by mistake; title containing only whitespace/emoji stripped by trim.

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/a2c80c7fb534f19f. Report an issue: GitHub.