jackwener/OpenCLI · error · ArgumentError
Too many media items: ${inputs.length}
Error message
Too many media items: ${inputs.length} What it means
validateMixedMediaItems throws this ArgumentError when more than MAX_MEDIA_ITEMS (10) media paths are supplied to the instagram post command. Instagram carousels support at most 10 items, so the library enforces the platform limit client-side rather than letting Instagram reject the upload mid-flight.
Source
Thrown at clis/instagram/post.js:92
!!dialog.querySelector('textarea, [contenteditable="true"], input[type="file"]')
|| /write a caption|add location|advanced settings|select from computer|crop|filters|adjustments|sharing/.test((dialog.textContent || '').toLowerCase())
);
const settled = !shared && !composerOpen && !/sharing/.test(visibleText);
return { ok: shared, failed, settled, url: /\\/p\\//.test(url) ? url : '' };
})()
`;
}
function requirePage(page) {
if (!page)
throw new CommandExecutionError('Browser session required for instagram post');
return page;
}
function validateMixedMediaItems(inputs) {
if (!inputs.length) {
throw new ArgumentError('Argument "media" is required.', 'Provide --media /path/to/file.jpg or --media /path/a.jpg,/path/b.mp4');
}
if (inputs.length > MAX_MEDIA_ITEMS) {
throw new ArgumentError(`Too many media items: ${inputs.length}`, `Instagram carousel posts support at most ${MAX_MEDIA_ITEMS} items`);
}
const items = inputs.map((input) => {
const resolved = path.resolve(String(input || '').trim());
if (!resolved) {
throw new ArgumentError('Media path cannot be empty');
}
if (!fs.existsSync(resolved)) {
throw new ArgumentError(`Media file not found: ${resolved}`);
}
const ext = path.extname(resolved).toLowerCase();
if (SUPPORTED_IMAGE_EXTENSIONS.has(ext)) {
return { type: 'image', filePath: resolved };
}
if (SUPPORTED_VIDEO_EXTENSIONS.has(ext)) {
return { type: 'video', filePath: resolved };
}
throw new ArgumentError(`Unsupported media format: ${ext}`, 'Supported formats: images (.jpg, .jpeg, .png, .webp) and videos (.mp4)');
});View on GitHub (pinned to 49907e53dc)
Solutions
- Reduce the media list to 10 or fewer items for a single carousel post.
- Split the content into multiple posts (e.g. two carousels of ≤10 items each).
- Count items programmatically before invoking and fail/branch early in your own code.
- Deduplicate the list — accidental duplicate paths can push a valid set over the limit.
- Pick the 10 best assets if the goal is one post; Instagram will reject >10 regardless.
Example fix
// before
const files = fs.readdirSync('./assets').map(f => './assets/' + f).join(',');
await run(['instagram', 'post', '--media', files]); // throws when > 10
// after
const files = fs.readdirSync('./assets').map(f => './assets/' + f).slice(0, 10).join(',');
if (fs.readdirSync('./assets').length > 10) console.warn('Truncated carousel to 10 items');
await run(['instagram', 'post', '--media', files]); Defensive patterns
Strategy: validation
Validate before calling
const MAX_MEDIA_ITEMS = 10;
const items = mediaArg.split(',').map(s => s.trim()).filter(Boolean);
if (items.length > MAX_MEDIA_ITEMS) {
throw new Error(`Carousel supports at most ${MAX_MEDIA_ITEMS} items; got ${items.length}. Split into multiple posts.`);
} Try / catch
try {
await cli.run('instagram post', { media: mediaArg });
} catch (e) {
if (e instanceof ArgumentError && /^Too many media items:/.test(e.message)) {
const count = Number(e.message.match(/Too many media items: (\d+)/)?.[1]);
console.error(`Trim media list from ${count} to 10 items, or post multiple carousels`);
} else throw e;
} Prevention
- Cap media lists at 10 items before invoking
- Slice or chunk asset folders into groups of ≤10
- Deduplicate paths so accidental repeats don't push over the limit
- Remember the cap is Instagram's carousel limit (10), not a CLI setting
- Split large sets into sequential posts in your automation
When it happens
Trigger: Calling the instagram post command with --media containing 11+ comma-separated file paths, or programmatically passing an array/CSV of media that exceeds 10 entries.
Common situations: Automation scripts dump an entire folder of images into --media; users assume the limit is higher (some platforms allow more) or believe extra items are silently dropped; a config lists all campaign assets and the developer forgot the 10-item carousel cap.
Related errors
- 标题不能超过 30 字
- 正文不能超过 1000 字
- index must be a positive integer
- Instagram URL is required
- Argument "media" is required.
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/0bfc8579b226bbe6.
Report an issue: GitHub.