jackwener/OpenCLI · error · ArgumentError
Story media file not found: ${resolved}
Error message
Story media file not found: ${resolved} What it means
An ArgumentError thrown by normalizeStoryMediaItem() when the resolved media path does not exist on disk (fs.existsSync(resolved) is false). The path is resolved to an absolute path first, so the message shows the exact file it looked for.
Source
Thrown at clis/instagram/story.js:31
return page;
}
function validateInstagramStoryArgs(kwargs) {
if (kwargs.media === undefined) {
throw new ArgumentError('Argument "media" is required.', 'Provide --media /path/to/file.jpg or --media /path/to/file.mp4');
}
}
function normalizeStoryMediaItem(kwargs) {
const raw = String(kwargs.media ?? '').trim();
const parts = raw.split(',').map((part) => part.trim()).filter(Boolean);
if (parts.length === 0) {
throw new ArgumentError('Argument "media" is required.', 'Provide --media /path/to/file.jpg or --media /path/to/file.mp4');
}
if (parts.length > 1) {
throw new ArgumentError('Instagram story currently supports a single media item.', 'Provide one image or one video path with --media');
}
const resolved = path.resolve(parts[0]);
if (!fs.existsSync(resolved)) {
throw new ArgumentError(`Story media file not found: ${resolved}`);
}
const ext = path.extname(resolved).toLowerCase();
if (SUPPORTED_STORY_IMAGE_EXTENSIONS.has(ext)) {
return { type: 'image', filePath: resolved };
}
if (SUPPORTED_STORY_VIDEO_EXTENSIONS.has(ext)) {
return { type: 'video', filePath: resolved };
}
throw new ArgumentError(`Unsupported story media format: ${ext}`, 'Supported formats: images (.jpg, .jpeg, .png, .webp) and videos (.mp4)');
}
async function resolveCurrentUsername(page, currentUserId = '') {
if (!currentUserId)
return '';
const runtimeInfo = await resolveInstagramRuntimeInfo(page);
const apiResult = await page.evaluate(`
(async () => {
const userId = ${JSON.stringify(currentUserId)};
const appId = ${JSON.stringify(runtimeInfo.appId || '')};View on GitHub (pinned to 49907e53dc)
Solutions
- Verify the file exists: ls /exact/resolved/path from the error message
- Use an absolute path, or run the command from the directory containing the file
- Check filename spelling and case (filesystems are case-sensitive on Linux)
- Ensure any download/export step completed before invoking the story command
Example fix
// before
await story({ media: 'photo.jpg' }); // run from wrong cwd
// after
await story({ media: path.resolve(__dirname, 'assets/photo.jpg') }); Defensive patterns
Strategy: validation
Validate before calling
import fs from 'node:fs'; import path from 'node:path';
const resolved = path.resolve(mediaArg);
if (!fs.existsSync(resolved)) throw new Error(`File not found: ${resolved} (cwd: ${process.cwd()})`); Type guard
function isExistingFile(p) { try { return fs.statSync(p).isFile(); } catch { return false; } } Try / catch
try {
await postStory({ media: mediaArg });
} catch (e) {
if (/Story media file not found/.test(e.message)) {
console.error('Check the path and cwd:', e.message);
} else throw e;
} Prevention
- Use absolute paths (path.resolve) instead of cwd-relative ones
- Verify the file exists before invoking the command
- Confirm earlier download/generation steps finished first
- Watch out for case-sensitivity on Linux filesystems
When it happens
Trigger: --media points to a path that fs.existsSync cannot find: typo, wrong working directory for a relative path, deleted/moved file, or a directory instead of a file.
Common situations: Relative path assumptions (script run from a different cwd), files not yet downloaded/generated before the story command runs, Windows-style paths on Linux, or case-sensitive filename mismatches.
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
- ${label}文件不存在: ${resolved}
- FILE_NOT_FOUND
- File not found: ${path}
- Cover image file not found: ${imagePath}
- Video file not found: ${filePath}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/02d7043d14c8a71c.
Report an issue: GitHub.