{"record":{"id":"749aa95df7fdcc27","repo":"jackwener/OpenCLI","slug":"argument-media-is-required-749aa9","errorCode":null,"errorMessage":"Argument \"media\" is required.","messagePattern":"Argument \"media\" is required\\.","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/instagram/story.js","lineNumber":17,"sourceCode":"import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { publishStoryViaPrivateApi, resolveInstagramPrivatePublishConfig, } from './_shared/private-publish.js';\nimport { resolveCurrentUserId, resolveInstagramRuntimeInfo } from './_shared/runtime-info.js';\nimport { INSTAGRAM_HOME_URL } from './_shared/navigation.js';\nconst SUPPORTED_STORY_IMAGE_EXTENSIONS = new Set(['.jpg', '.jpeg', '.png', '.webp']);\nconst SUPPORTED_STORY_VIDEO_EXTENSIONS = new Set(['.mp4']);\nfunction requirePage(page) {\n    if (!page)\n        throw new CommandExecutionError('Browser session required for instagram story');\n    return page;\n}\nfunction validateInstagramStoryArgs(kwargs) {\n    if (kwargs.media === undefined) {\n        throw new ArgumentError('Argument \"media\" is required.', 'Provide --media /path/to/file.jpg or --media /path/to/file.mp4');\n    }\n}\nfunction normalizeStoryMediaItem(kwargs) {\n    const raw = String(kwargs.media ?? '').trim();\n    const parts = raw.split(',').map((part) => part.trim()).filter(Boolean);\n    if (parts.length === 0) {\n        throw new ArgumentError('Argument \"media\" is required.', 'Provide --media /path/to/file.jpg or --media /path/to/file.mp4');\n    }\n    if (parts.length > 1) {\n        throw new ArgumentError('Instagram story currently supports a single media item.', 'Provide one image or one video path with --media');\n    }\n    const resolved = path.resolve(parts[0]);\n    if (!fs.existsSync(resolved)) {\n        throw new ArgumentError(`Story media file not found: ${resolved}`);\n    }\n    const ext = path.extname(resolved).toLowerCase();\n    if (SUPPORTED_STORY_IMAGE_EXTENSIONS.has(ext)) {\n        return { type: 'image', filePath: resolved };","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/story.js#L1-L35","documentation":"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.","triggerScenarios":"Invoking the instagram story command without passing --media (kwargs.media === undefined).","commonSituations":"Forgetting the --media flag on the CLI, typos like --file or --image, or calling the underlying function programmatically without a media key.","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"],"exampleFix":"// before\nawait story({}); // missing media\n// after\nawait story({ media: '/path/to/photo.jpg' });","handlingStrategy":"validation","validationCode":"function assertMedia(kwargs) {\n  if (kwargs?.media === undefined) {\n    throw new Error('Usage: instagram story --media /path/to/file.jpg|.mp4');\n  }\n}","typeGuard":"function hasMedia(k) { return k !== null && typeof k === 'object' && typeof k.media === 'string' && k.media.length > 0; }","tryCatchPattern":"try {\n  await postStory(kwargs);\n} catch (e) {\n  if (/Argument \\\\\"media\\\\\" is required/.test(e.message)) {\n    console.error('Pass --media <file.jpg|.mp4>');\n  } else throw e;\n}","preventionTips":["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"],"tags":["arguments","validation","cli","instagram"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}