{"record":{"id":"02d7043d14c8a71c","repo":"jackwener/OpenCLI","slug":"story-media-file-not-found-resolved","errorCode":null,"errorMessage":"Story media file not found: ${resolved}","messagePattern":"Story media file not found: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/instagram/story.js","lineNumber":31,"sourceCode":"    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 };\n    }\n    if (SUPPORTED_STORY_VIDEO_EXTENSIONS.has(ext)) {\n        return { type: 'video', filePath: resolved };\n    }\n    throw new ArgumentError(`Unsupported story media format: ${ext}`, 'Supported formats: images (.jpg, .jpeg, .png, .webp) and videos (.mp4)');\n}\nasync function resolveCurrentUsername(page, currentUserId = '') {\n    if (!currentUserId)\n        return '';\n    const runtimeInfo = await resolveInstagramRuntimeInfo(page);\n    const apiResult = await page.evaluate(`\n    (async () => {\n      const userId = ${JSON.stringify(currentUserId)};\n      const appId = ${JSON.stringify(runtimeInfo.appId || '')};","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/story.js#L13-L49","documentation":"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.","triggerScenarios":"--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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait story({ media: 'photo.jpg' }); // run from wrong cwd\n// after\nawait story({ media: path.resolve(__dirname, 'assets/photo.jpg') });","handlingStrategy":"validation","validationCode":"import fs from 'node:fs'; import path from 'node:path';\nconst resolved = path.resolve(mediaArg);\nif (!fs.existsSync(resolved)) throw new Error(`File not found: ${resolved} (cwd: ${process.cwd()})`);","typeGuard":"function isExistingFile(p) { try { return fs.statSync(p).isFile(); } catch { return false; } }","tryCatchPattern":"try {\n  await postStory({ media: mediaArg });\n} catch (e) {\n  if (/Story media file not found/.test(e.message)) {\n    console.error('Check the path and cwd:', e.message);\n  } else throw e;\n}","preventionTips":["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"],"tags":["filesystem","validation","file-not-found","instagram"],"backgroundTag":"file-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}