{"record":{"id":"922941d57ce6e85f","repo":"jackwener/OpenCLI","slug":"invalid-instagram-url-raw","errorCode":null,"errorMessage":"Invalid Instagram URL: ${raw}","messagePattern":"Invalid Instagram URL: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/instagram/download.js","lineNumber":53,"sourceCode":"        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;\n    if (segments.length >= 2 && SUPPORTED_KINDS.has(segments[0])) {\n        kind = segments[0];\n        shortcode = segments[1];\n    }\n    else if (segments.length >= 3 && SUPPORTED_KINDS.has(segments[1])) {\n        kind = segments[1];\n        shortcode = segments[2];","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/download.js#L35-L71","documentation":"Thrown by parseInstagramMediaTarget when the raw argument cannot be parsed as a URL at all (new URL(raw) throws). The library requires a well-formed Instagram post/reel/tv URL before doing any further checks, so it fails fast with an ArgumentError. The hint tells the expected shape: https://www.instagram.com/p/<shortcode>/ or /reel/<shortcode>/.","triggerScenarios":"Calling the instagram download target with a string that is not a parseable URL: a bare shortcode ('Cxyz123'), a value with unencoded spaces or characters, an empty string, or text with copy/paste artifacts.","commonSituations":"Users paste just the shortcode instead of the full link; shell escaping strips or mangles the URL; the argument is read from config/env and is empty; a URL containing '&', '(' or other shell metacharacters was not quoted.","solutions":["Pass the full post URL, e.g. https://www.instagram.com/p/<shortcode>/, quoted for your shell","Trim whitespace and URL-encode stray characters in the input before calling","Check where the value comes from (env var/config/clipboard) and fix the source of the empty or partial string"],"exampleFix":"// before\nigdl Cxyz123\n// after\nigdl 'https://www.instagram.com/p/Cxyz123/'","handlingStrategy":"validation","validationCode":"function isValidInstagramUrl(raw) {\n  try { const u = new URL(raw); return ['http:','https:'].includes(u.protocol) && u.hostname.toLowerCase().endsWith('instagram.com'); }\n  catch { return false; }\n}\nif (!isValidInstagramUrl(raw)) throw new Error('Provide a full https://www.instagram.com/p/<shortcode>/ link');","typeGuard":"function isInstagramUrl(v) {\n  if (typeof v !== 'string' || v.length === 0) return false;\n  try { const u = new URL(v); return (u.protocol === 'http:' || u.protocol === 'https:') && (u.hostname === 'instagram.com' || u.hostname.endsWith('.instagram.com')); }\n  catch { return false; }\n}","tryCatchPattern":"try {\n  await igDownload(raw);\n} catch (e) {\n  if (e.name === 'ArgumentError' && /Invalid Instagram URL/.test(e.message)) {\n    console.error('Please pass the full post URL, e.g. https://www.instagram.com/p/<shortcode>/');\n  } else throw e;\n}","preventionTips":["Always pass the full https:// URL copied via the post's Copy Link","Quote URLs in the shell to avoid escaping artifacts","Validate URL shape in scripts before invoking the CLI"],"tags":["cli","argument-validation","url-parsing"],"backgroundTag":"invalid-url-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}