{"record":{"id":"1f552631ca462a79","repo":"jackwener/OpenCLI","slug":"instagram-url-is-required","errorCode":null,"errorMessage":"Instagram URL is required","messagePattern":"Instagram URL is required","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/instagram/download.js","lineNumber":46,"sourceCode":"}\n/** A shortcode is the media id written in Instagram's base64 alphabet. */\nexport function shortcodeToMediaId(shortcode) {\n    const raw = String(shortcode || '');\n    if (!raw) return '';\n    let mediaId = 0n;\n    for (const character of raw) {\n        const digit = INSTAGRAM_SHORTCODE_ALPHABET.indexOf(character);\n        if (digit < 0) return '';\n        mediaId = mediaId * 64n + BigInt(digit);\n        if (mediaId > MAX_INSTAGRAM_MEDIA_ID) return '';\n    }\n    if (mediaId <= 0n) return '';\n    return mediaId.toString();\n}\nexport function parseInstagramMediaTarget(input) {\n    const raw = String(input || '').trim();\n    if (!raw) {\n        throw new ArgumentError('Instagram URL is required', 'Expected https://www.instagram.com/p/... or https://www.instagram.com/reel/...');\n    }\n    let url;\n    try {\n        url = new URL(raw);\n    }\n    catch {\n        throw new ArgumentError(`Invalid Instagram URL: ${raw}`, 'Expected https://www.instagram.com/p/<shortcode>/ or /reel/<shortcode>/');\n    }\n    if (!['http:', 'https:'].includes(url.protocol)) {\n        throw new ArgumentError(`Unsupported URL protocol: ${url.protocol}`);\n    }\n    const host = url.hostname.toLowerCase();\n    if (host !== INSTAGRAM_HOST_SUFFIX && !host.endsWith(`.${INSTAGRAM_HOST_SUFFIX}`)) {\n        throw new ArgumentError(`Unsupported host: ${host}`, 'Only instagram.com URLs are supported');\n    }\n    const segments = url.pathname.split('/').filter(Boolean);\n    let kind;\n    let shortcode;","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/download.js#L28-L64","documentation":"parseInstagramMediaTarget throws an ArgumentError because the input string is empty after trimming (or null/undefined). The download command requires a concrete media target — a post/reel URL or media id — to resolve a media identifier.","triggerScenarios":"Calling instagram download with no argument; passing an empty string or whitespace; a variable/placeholder in a script that failed to interpolate; environment/config value unset.","commonSituations":"Forgetting the URL argument on the CLI; CI scripts where the URL comes from an unset env var; copying only the Instagram page title instead of the URL; shell quoting eating the argument.","solutions":["Pass a full Instagram media URL, e.g. https://www.instagram.com/p/<code>/ or https://www.instagram.com/reel/<code>/","Fix the variable/env/config that should contain the URL and confirm it is non-empty before invoking","Quote the URL in shells so special characters don't get dropped","Add an early check in your script: if (!url) throw ... before calling the CLI"],"exampleFix":"// before\ninstagram download \"$IG_URL\"\n// after\nif [ -z \"${IG_URL:-}\" ]; then echo 'IG_URL is not set'; exit 1; fi\ninstagram download \"$IG_URL\"","handlingStrategy":"validation","validationCode":"function requireInstagramUrl(input) {\n  const raw = String(input || '').trim();\n  if (!raw) throw new Error('Instagram URL is required');\n  if (!/^https:\\/\\/www\\.instagram\\.com\\/(p|reel)\\//.test(raw)) {\n    throw new Error('Expected https://www.instagram.com/p/... or /reel/... URL');\n  }\n  return raw;\n}","typeGuard":"function isInstagramMediaUrl(v) {\n  return typeof v === 'string' && /^https:\\/\\/www\\.instagram\\.com\\/(p|reel)\\/[A-Za-z0-9_-]+\\//.test(v.trim());\n}","tryCatchPattern":"try {\n  await downloadInstagramMedia(input);\n} catch (e) {\n  if (e.name === 'ArgumentError' && /Instagram URL is required/.test(e.message)) {\n    console.error('Provide a post or reel URL, e.g. https://www.instagram.com/p/<code>/');\n  } else throw e;\n}","preventionTips":["Always pass a full p/ or reel/ URL","Check env/config variables are set before invoking","Quote URLs in shell commands","Trim and validate input early in scripts"],"tags":["instagram","argument-error","validation","missing-input"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}