{"record":{"id":"b749a2ab3b39bc15","repo":"jackwener/OpenCLI","slug":"unsupported-host-host","errorCode":null,"errorMessage":"Unsupported host: ${host}","messagePattern":"Unsupported host: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/instagram/download.js","lineNumber":60,"sourceCode":"}\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];\n    }\n    if (!kind || !shortcode) {\n        throw new ArgumentError(`Unsupported Instagram media URL: ${raw}`, 'Only /p/<shortcode>/, /reel/<shortcode>/, and /tv/<shortcode>/ links are supported');\n    }\n    if (!shortcodeToMediaId(shortcode)) {\n        throw new ArgumentError(`Invalid Instagram shortcode: ${shortcode}`, 'Copy the link straight from the post, without escaping it');\n    }","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/download.js#L42-L78","documentation":"Thrown by parseInstagramMediaTarget when the URL host is neither instagram.com nor a subdomain of it (INSTAGRAM_HOST_SUFFIX). The library only processes links hosted on Instagram domains.","triggerScenarios":"Passing a URL from another service (e.g. instagramez.com, fake-phishing mirror, imginn mirror, or a totally different site) to the Instagram download command.","commonSituations":"Using third-party Instagram viewer/mirror sites; typos in the domain (instagrarn.com); pasting a link to an embed or proxy service; phishing lookalike domains.","solutions":["Use a URL whose host is instagram.com or a subdomain like www.instagram.com","Correct any domain typos","Open the post in the official app/site and copy the canonical link"],"exampleFix":"// before\nhttps://imginn.com/p/Cxyz123/\n// after\nhttps://www.instagram.com/p/Cxyz123/","handlingStrategy":"validation","validationCode":"const u = new URL(raw);\nconst h = u.hostname.toLowerCase();\nif (h !== 'instagram.com' && !h.endsWith('.instagram.com')) throw new Error('Only instagram.com URLs are supported');","typeGuard":"function isInstagramHost(v) {\n  try { const h = new URL(v).hostname.toLowerCase(); return h === 'instagram.com' || h.endsWith('.instagram.com'); } catch { return false; }\n}","tryCatchPattern":"try {\n  await igDownload(raw);\n} catch (e) {\n  if (e.name === 'ArgumentError' && /Unsupported host/.test(e.message)) {\n    console.error('Open the post on instagram.com and copy the canonical link.');\n  } else throw e;\n}","preventionTips":["Only use links from the official instagram.com domain","Watch for typo/phishing mirror domains","Resolve third-party viewer links back to the original post"],"tags":["cli","url-parsing","host-validation"],"backgroundTag":"unsupported-host","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}