{"record":{"id":"c708690aaf64e7c3","repo":"jackwener/OpenCLI","slug":"argument-media-is-required","errorCode":null,"errorMessage":"Argument \"media\" is required.","messagePattern":"Argument \"media\" is required\\.","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/instagram/post.js","lineNumber":89,"sourceCode":"        || (/something went wrong/.test(visibleText) && /try again/.test(visibleText))\n      );\n      const composerOpen = dialogs.some((dialog) =>\n        !!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 };","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/post.js#L71-L107","documentation":"validateMixedMediaItems throws this ArgumentError when the --media value is empty after normalization (normalizePostMediaItems splits kwargs.media on commas and filters empties, leaving zero items). The instagram post command requires at least one media file; an empty list cannot produce a post or carousel, so the library fails fast with usage guidance in the hint argument.","triggerScenarios":"Invoking the instagram post command with no --media flag, --media '' (empty string), --media ',' or ' , ,' (only commas/whitespace), or kwargs.media being whitespace only — all produce an empty inputs array hitting the !inputs.length branch.","commonSituations":"A script builds the --media list dynamically (e.g. from a glob or variable) and the variable resolves to empty; a shell variable expansion drops the value; typos like --medias or --media= with nothing after the equals sign; CSV paths where all entries were filtered as nonexistent elsewhere upstream.","solutions":["Pass at least one existing media file: --media /path/to/file.jpg (or comma-separated list for a carousel).","Check the shell variable feeding --media is non-empty before invoking the command.","Fix flag typos — the flag is --media, and --media= must be followed by a path.","If paths are generated dynamically, guard the command invocation when the file list is empty.","Validate media existence/format first so only valid files are passed (see the sibling 'Media file not found' / 'Unsupported media format' errors)."],"exampleFix":"// before\nconst media = process.env.MEDIA_FILES || '';\nawait run(['instagram', 'post', '--media', media]); // throws if empty\n// after\nconst media = (process.env.MEDIA_FILES || '').trim();\nif (!media) throw new Error('MEDIA_FILES must contain at least one file path');\nawait run(['instagram', 'post', '--media', media]);","handlingStrategy":"validation","validationCode":"const media = String(kwargs.media ?? '').trim();\nconst items = media.split(',').map(s => s.trim()).filter(Boolean);\nif (!items.length) {\n  throw new Error('instagram post requires --media with at least one file, e.g. --media /path/to/file.jpg');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await cli.run('instagram post', { media: mediaArg });\n} catch (e) {\n  if (e instanceof ArgumentError && e.message === 'Argument \"media\" is required.') {\n    console.error('Usage: instagram post --media /path/a.jpg[,/path/b.mp4]');\n    process.exitCode = 2; // usage error, not retryable\n  } else throw e;\n}","preventionTips":["Check the --media variable is non-empty before invoking","Guard dynamic file lists: skip the command when the list is empty","Avoid passing bare commas or whitespace as --media","Double-check flag spelling (--media) and --media= usage","Build media lists with .filter(Boolean) after splitting"],"tags":["instagram","argument-error","missing-argument","input-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}