jackwener/OpenCLI · error · ArgumentError
Media file not found: ${resolved}
Error message
Media file not found: ${resolved} What it means
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.
Source
Thrown at clis/instagram/post.js:100
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)');
});
return items;
}
function normalizePostMediaItems(kwargs) {
const media = String(kwargs.media ?? '').trim();
return validateMixedMediaItems(media.split(',').map((part) => part.trim()).filter(Boolean));
}
function validateInstagramPostArgs(kwargs) {
const media = kwargs.media;View on GitHub (pinned to 49907e53dc)
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
Example fix
// before
await cli.post({ media: 'shot.png' }); // cwd mismatch -> not found
// after
import path from 'node:path';
await cli.post({ media: path.resolve(__dirname, './assets/shot.png') }); Defensive patterns
Strategy: validation
Validate before calling
import fs from 'node:fs';
import path from 'node:path';
function assertMediaFilesExist(media) {
const paths = String(media).split(',').map(p => p.trim()).filter(Boolean);
for (const p of paths) {
const resolved = path.resolve(p);
if (!fs.existsSync(resolved)) throw new Error(`Media file not found: ${resolved}`);
}
}
assertMediaFilesExist('/tmp/a.jpg,/tmp/b.mp4'); Type guard
function isExistingFile(p) {
try { return fs.statSync(path.resolve(p)).isFile(); } catch { return false; }
} Try / catch
try {
await cli.post({ media });
} catch (e) {
if (e instanceof ArgumentError && e.message.startsWith('Media file not found')) {
console.error('Fix the path:', e.message);
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- 封面文件不存在: ${path.resolve(coverPath)}
- ${label}文件不存在: ${resolved}
- archive search sort must be one of ${SORT_OPTIONS.join(', ')
- archive search mediatype must be one of ${MEDIATYPES.join(',
- archive search limit must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/89cbcb78d1c10e54.
Report an issue: GitHub.