{"record":{"id":"89cbcb78d1c10e54","repo":"jackwener/OpenCLI","slug":"media-file-not-found-resolved","errorCode":null,"errorMessage":"Media file not found: ${resolved}","messagePattern":"Media file not found: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/instagram/post.js","lineNumber":100,"sourceCode":"function 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));\n}\nfunction validateInstagramPostArgs(kwargs) {\n    const media = kwargs.media;","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/post.js#L82-L118","documentation":"validateMixedMediaItems resolves each comma-separated --media path and throws ArgumentError when fs.existsSync() reports the file does not exist. It fails fast before any browser automation starts, so no session is opened for invalid input. The message includes the fully resolved absolute path that was checked.","triggerScenarios":"Calling the instagram post command with --media pointing at a path that does not exist on disk, a typo'd filename, a relative path resolved against a different working directory, or a file deleted between argument parsing and posting.","commonSituations":"Hardcoded paths in scripts run from a different cwd; spaces in filenames that got split incorrectly; files in a container/CI that were never copied in; case-sensitive filesystems where the extension or name casing differs; macOS vs Linux path differences.","solutions":["Run ls on the exact resolved path printed in the error and fix typos","Pass an absolute path or cd to the directory containing the file before running","Verify the file exists at runtime (fs.existsSync) in scripts that generate media before invoking the command","In CI, add a step that uploads/copies the media artifact before the post step"],"exampleFix":"// before\nawait cli.post({ media: 'shot.png' }); // cwd mismatch -> not found\n// after\nimport path from 'node:path';\nawait cli.post({ media: path.resolve(__dirname, './assets/shot.png') });","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nimport path from 'node:path';\nfunction assertMediaFilesExist(media) {\n  const paths = String(media).split(',').map(p => p.trim()).filter(Boolean);\n  for (const p of paths) {\n    const resolved = path.resolve(p);\n    if (!fs.existsSync(resolved)) throw new Error(`Media file not found: ${resolved}`);\n  }\n}\nassertMediaFilesExist('/tmp/a.jpg,/tmp/b.mp4');","typeGuard":"function isExistingFile(p) {\n  try { return fs.statSync(path.resolve(p)).isFile(); } catch { return false; }\n}","tryCatchPattern":"try {\n  await cli.post({ media });\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.startsWith('Media file not found')) {\n    console.error('Fix the path:', e.message);\n  } else throw e;\n}","preventionTips":["Always pass absolute paths (path.resolve) so cwd changes cannot break scripts","fs.existsSync each media path before invoking the command","In CI, verify artifacts were uploaded/copied before the post step","Quote paths with spaces in shell scripts"],"tags":["argument-error","file-not-found","validation"],"backgroundTag":"file-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}