jackwener/OpenCLI · error · ArgumentError
Argument "media" is required.
Error message
Argument "media" is required.
What it means
An ArgumentError thrown by validateInstagramStoryArgs() when kwargs.media is undefined. The story command cannot run without a media file path, so this is an upfront argument validation failure with a hint pointing at the --media flag.
Source
Thrown at clis/instagram/story.js:17
import * as fs from 'node:fs';
import * as path from 'node:path';
import { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
import { publishStoryViaPrivateApi, resolveInstagramPrivatePublishConfig, } from './_shared/private-publish.js';
import { resolveCurrentUserId, resolveInstagramRuntimeInfo } from './_shared/runtime-info.js';
import { INSTAGRAM_HOME_URL } from './_shared/navigation.js';
const SUPPORTED_STORY_IMAGE_EXTENSIONS = new Set(['.jpg', '.jpeg', '.png', '.webp']);
const SUPPORTED_STORY_VIDEO_EXTENSIONS = new Set(['.mp4']);
function requirePage(page) {
if (!page)
throw new CommandExecutionError('Browser session required for instagram story');
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 };View on GitHub (pinned to 49907e53dc)
Solutions
- Re-run the command with --media /path/to/file.jpg (or .mp4)
- Check flag spelling — it must be exactly --media
- If calling programmatically, include a `media` property in the kwargs object
- Wrap calls in argument validation that checks media before invoking
Example fix
// before
await story({}); // missing media
// after
await story({ media: '/path/to/photo.jpg' }); Defensive patterns
Strategy: validation
Validate before calling
function assertMedia(kwargs) {
if (kwargs?.media === undefined) {
throw new Error('Usage: instagram story --media /path/to/file.jpg|.mp4');
}
} Type guard
function hasMedia(k) { return k !== null && typeof k === 'object' && typeof k.media === 'string' && k.media.length > 0; } Try / catch
try {
await postStory(kwargs);
} catch (e) {
if (/Argument \\"media\\" is required/.test(e.message)) {
console.error('Pass --media <file.jpg|.mp4>');
} else throw e;
} Prevention
- Always pass --media explicitly; never rely on defaults
- Use exact flag spelling: --media
- For programmatic use, validate kwargs.media before calling
- Add CLI-level required-arg checks with usage hints
When it happens
Trigger: Invoking the instagram story command without passing --media (kwargs.media === undefined).
Common situations: Forgetting the --media flag on the CLI, typos like --file or --image, or calling the underlying function programmatically without a media key.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- ${label} is required
- ${label} must be a positive integer
- ${label} must be <= ${maxValue}
- dblp ${label} must be a positive integer
- dblp ${label} must be <= ${maxValue}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/749aa95df7fdcc27.
Report an issue: GitHub.