jackwener/OpenCLI · error · ArgumentError

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

Error message

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

What it means

validateImagePaths caps attachments at MAX_IMAGES; supplying more comma-separated image paths than allowed throws an ArgumentError before any upload begins.

Source

Thrown at clis/weibo/publish.js:55

const TEXTAREA_SELECTORS = [
    'textarea[placeholder*="有什么新鲜事"]',
    'textarea[placeholder*="新鲜事"]',
    'textarea._input_13iqr_8',
];
const FILE_INPUT_SELECTOR = 'input[type="file"][class*="_file_"]';

function validateText(text) {
    const t = String(text ?? '').trim();
    if (!t) throw new ArgumentError('weibo publish text cannot be empty');
    if (t.length > 2000) throw new ArgumentError('weibo publish text exceeds 2000 characters');
    return t;
}

function validateImagePaths(raw) {
    if (!raw) return [];
    const paths = raw.split(',').map(s => s.trim()).filter(Boolean);
    if (paths.length > MAX_IMAGES) {
        throw new ArgumentError(`Too many images: ${paths.length} (max ${MAX_IMAGES})`);
    }
    return paths.map(p => {
        const absPath = path.resolve(p);
        const ext = path.extname(absPath).toLowerCase();
        if (!SUPPORTED_EXTENSIONS.has(ext)) {
            throw new ArgumentError(`Unsupported image format "${ext}". Supported: jpg, png, gif, webp`);
        }
        const stat = fs.statSync(absPath, { throwIfNoEntry: false });
        if (!stat || !stat.isFile()) {
            throw new ArgumentError(`Not a valid file: ${absPath}`);
        }
        return absPath;
    });
}

cli({
    site: 'weibo',
    name: 'publish',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Reduce the image list to at most MAX_IMAGES entries
  2. Publish in multiple batches
  3. Deduplicate the path list before passing it

Example fix

// before
--images img1.jpg,img2.jpg,img3.jpg,img4.jpg,img5.jpg,img6.jpg
// after (if MAX_IMAGES is 4)
weibo publish --text "..." --images img1.jpg,img2.jpg,img3.jpg,img4.jpg
Defensive patterns

Strategy: validation

Validate before calling

const MAX_IMAGES = 4; // match clis/weibo/publish.js
const paths = images.split(',').map(s => s.trim()).filter(Boolean);
if (paths.length > MAX_IMAGES) throw new Error(`max ${MAX_IMAGES} images`);

Try / catch

try {
  await cli.run(['weibo', 'publish', '--text', text, '--images', images]);
} catch (err) {
  if (/Too many images/.test(err.message)) {
    console.error('Split the upload into batches');
  } else throw err;
}

Prevention

When it happens

Trigger: Calling `weibo publish --images` with a comma-separated list containing more entries than MAX_IMAGES (defined in clis/weibo/publish.js).

Common situations: Globbing a directory of screenshots into the flag; reusing a list built for another tool with a higher limit; accidental duplicate paths.

Related errors


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