jackwener/OpenCLI · error · ArgumentError

Too many images: ${imagePaths.length} (max ${MAX_IMAGES})

Error message

Too many images: ${imagePaths.length} (max ${MAX_IMAGES})

What it means

ArgumentError thrown when more than MAX_IMAGES (9) image paths are supplied, matching XHS's per-note image limit. The check runs before any browser automation so failures are fast.

Source

Thrown at clis/xiaohongshu/publish.js:1208

            : [];
        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');
        }
        // ── Step 2: Select 图文 (image+text) note type if tabs are present ─────────
        const tabResult = await selectImageTextTab(page);
        const surface = await waitForPublishSurfaceState(page, tabResult?.ok ? 5_000 : 2_000);
        if (surface.state === 'video_surface') {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Trim the --images list to 9 or fewer paths
  2. Split into multiple notes if you have more than 9 images
  3. Generate the list programmatically with a limit: files.slice(0, 9).join(',')

Example fix

// before
--images "$(ls photos/*.jpg | tr '\n' ',')"   # may exceed 9
// after
--images "$(ls photos/*.jpg | head -9 | tr '\n' ',')"
Defensive patterns

Strategy: validation

Validate before calling

const paths = imagesFlag.split(',').map(s => s.trim()).filter(Boolean);
if (paths.length > 9) throw new Error(`Only 9 images allowed, got ${paths.length}`);

Type guard

function withinImageLimit(paths) {
  return Array.isArray(paths) && paths.length >= 1 && paths.length <= 9;
}

Try / catch

try {
  await publish(page, { images: imagesFlag, ...rest });
} catch (e) {
  if (String(e.message).startsWith('Too many images')) {
    const trimmed = imagesFlag.split(',').slice(0, 9).join(',');
    // retry with first 9 images
  } else throw e;
}

Prevention

When it happens

Trigger: Upload mode with --images containing more than 9 comma-separated paths, or text-image mode where the accompanying images list exceeds 9 entries.

Common situations: Batch-exporting many photos and passing them all at once; building the --images list from a glob/directory listing that yields >9 files; forgetting XHS's hard cap of 9 images per note.

Related errors


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