{"record":{"id":"0bfc8579b226bbe6","repo":"jackwener/OpenCLI","slug":"too-many-media-items-inputs-length","errorCode":null,"errorMessage":"Too many media items: ${inputs.length}","messagePattern":"Too many media items: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/instagram/post.js","lineNumber":92,"sourceCode":"        !!dialog.querySelector('textarea, [contenteditable=\"true\"], input[type=\"file\"]')\n        || /write a caption|add location|advanced settings|select from computer|crop|filters|adjustments|sharing/.test((dialog.textContent || '').toLowerCase())\n      );\n      const settled = !shared && !composerOpen && !/sharing/.test(visibleText);\n      return { ok: shared, failed, settled, url: /\\\\/p\\\\//.test(url) ? url : '' };\n    })()\n  `;\n}\nfunction requirePage(page) {\n    if (!page)\n        throw new CommandExecutionError('Browser session required for instagram post');\n    return page;\n}\nfunction validateMixedMediaItems(inputs) {\n    if (!inputs.length) {\n        throw new ArgumentError('Argument \"media\" is required.', 'Provide --media /path/to/file.jpg or --media /path/a.jpg,/path/b.mp4');\n    }\n    if (inputs.length > MAX_MEDIA_ITEMS) {\n        throw new ArgumentError(`Too many media items: ${inputs.length}`, `Instagram carousel posts support at most ${MAX_MEDIA_ITEMS} items`);\n    }\n    const items = inputs.map((input) => {\n        const resolved = path.resolve(String(input || '').trim());\n        if (!resolved) {\n            throw new ArgumentError('Media path cannot be empty');\n        }\n        if (!fs.existsSync(resolved)) {\n            throw new ArgumentError(`Media file not found: ${resolved}`);\n        }\n        const ext = path.extname(resolved).toLowerCase();\n        if (SUPPORTED_IMAGE_EXTENSIONS.has(ext)) {\n            return { type: 'image', filePath: resolved };\n        }\n        if (SUPPORTED_VIDEO_EXTENSIONS.has(ext)) {\n            return { type: 'video', filePath: resolved };\n        }\n        throw new ArgumentError(`Unsupported media format: ${ext}`, 'Supported formats: images (.jpg, .jpeg, .png, .webp) and videos (.mp4)');\n    });","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/post.js#L74-L110","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst files = fs.readdirSync('./assets').map(f => './assets/' + f).join(',');\nawait run(['instagram', 'post', '--media', files]); // throws when > 10\n// after\nconst files = fs.readdirSync('./assets').map(f => './assets/' + f).slice(0, 10).join(',');\nif (fs.readdirSync('./assets').length > 10) console.warn('Truncated carousel to 10 items');\nawait run(['instagram', 'post', '--media', files]);","handlingStrategy":"validation","validationCode":"const MAX_MEDIA_ITEMS = 10;\nconst items = mediaArg.split(',').map(s => s.trim()).filter(Boolean);\nif (items.length > MAX_MEDIA_ITEMS) {\n  throw new Error(`Carousel supports at most ${MAX_MEDIA_ITEMS} items; got ${items.length}. Split into multiple posts.`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await cli.run('instagram post', { media: mediaArg });\n} catch (e) {\n  if (e instanceof ArgumentError && /^Too many media items:/.test(e.message)) {\n    const count = Number(e.message.match(/Too many media items: (\\d+)/)?.[1]);\n    console.error(`Trim media list from ${count} to 10 items, or post multiple carousels`);\n  } else throw e;\n}","preventionTips":["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"],"tags":["instagram","argument-error","limit-exceeded","carousel"],"backgroundTag":"argument-limit-exceeded","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}