{"record":{"id":"c7e0a7c8da0fd991","repo":"jackwener/OpenCLI","slug":"media-path-cannot-be-empty","errorCode":null,"errorMessage":"Media path cannot be empty","messagePattern":"Media path cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/instagram/post.js","lineNumber":97,"sourceCode":"    })()\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    });\n    return items;\n}\nfunction normalizePostMediaItems(kwargs) {\n    const media = String(kwargs.media ?? '').trim();\n    return validateMixedMediaItems(media.split(',').map((part) => part.trim()).filter(Boolean));","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/post.js#L79-L115","documentation":"validateMixedMediaItems throws this ArgumentError when a media entry resolves to an empty string. Each --media item is trimmed and passed through path.resolve; if the input string is empty/falsy after trimming, path.resolve('') would return the process CWD, so the library explicitly checks !resolved and rejects it to avoid silently posting the working directory.","triggerScenarios":"In practice this fires when an item in the media list is an empty/whitespace-only entry that survives the split/filter (e.g. a path built by joining strings where one segment was empty and the trim/resolve combination yields falsy input), or when validateMixedMediaItems is called directly with [''].","commonSituations":"Template/config strings like \"a.jpg,,b.jpg\" with stray empty entries; script string concatenation producing \"dir/\" + undefined; paths supplied via environment variables that are unset for some entries; programmatic use of the exported validator with unnormalized input.","solutions":["Remove empty entries from the media list before calling the command (filter out blank strings after splitting on commas).","Interpolate path variables safely — use template literals or path.join instead of string concatenation with possibly-undefined values.","Check that every environment/config variable supplying a path is set and non-blank.","Pre-validate each entry with a small guard in your own code and skip or report empty ones.","If calling the validator programmatically, normalize input the same way normalizePostMediaItems does (split, trim, filter(Boolean))."],"exampleFix":"// before\nconst media = [baseDir + sep + name, extraPath].join(','); // name may be undefined -> empty entry\nawait run(['instagram', 'post', '--media', media]);\n// after\nconst media = [name && path.join(baseDir, name), extraPath].filter(Boolean).join(',');\nif (!media) throw new Error('No valid media paths');\nawait run(['instagram', 'post', '--media', media]);","handlingStrategy":"validation","validationCode":"const items = mediaArg.split(',').map(s => s.trim()).filter(Boolean);\nitems.forEach((item, i) => {\n  if (!item) throw new Error(`Media entry #${i + 1} is empty`);\n  if (!item.trim()) throw new Error(`Media entry #${i + 1} is whitespace-only`);\n});","typeGuard":"function isNonEmptyPath(entry) {\n  return typeof entry === 'string' && entry.trim().length > 0;\n}","tryCatchPattern":"try {\n  await cli.run('instagram post', { media: mediaArg });\n} catch (e) {\n  if (e instanceof ArgumentError && e.message === 'Media path cannot be empty') {\n    console.error('A media list entry was empty — remove blank entries between commas');\n  } else throw e;\n}","preventionTips":["Always .split(',').map(trim).filter(Boolean) before building --media","Never concatenate paths with possibly-undefined variables — use path.join","Validate config/env values are set before interpolating into path lists","Avoid hand-written lists with trailing/double commas like \"a.jpg,,b.jpg\"","Normalize input the same way normalizePostMediaItems does before calling validators directly"],"tags":["instagram","argument-error","empty-path","input-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}