{"record":{"id":"2c7b61d5b45d95c1","repo":"jackwener/OpenCLI","slug":"invalid-instagram-shortcode-shortcode","errorCode":null,"errorMessage":"Invalid Instagram shortcode: ${shortcode}","messagePattern":"Invalid Instagram shortcode: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/instagram/download.js","lineNumber":77,"sourceCode":"    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    }\n    return {\n        kind: kind,\n        shortcode,\n        canonicalUrl: `https://www.instagram.com/${kind}/${shortcode}/`,\n    };\n}\nexport function buildInstagramDownloadItems(shortcode, items) {\n    if (!Array.isArray(items)) {\n        throw new CommandExecutionError('Instagram media metadata returned a malformed media list');\n    }\n    return items.map((item, index) => {\n        if (!item || typeof item !== 'object' || !['image', 'video'].includes(item.type)) {\n            throw new CommandExecutionError(`Instagram media metadata returned malformed media item #${index + 1}`);\n        }\n        let downloadUrl;\n        try {\n            downloadUrl = new URL(String(item.url || ''));","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/download.js#L59-L95","documentation":"Thrown by parseInstagramMediaTarget when the extracted shortcode cannot be converted to a media id by shortcodeToMediaId (it returned a falsy value). This means the shortcode is structurally invalid — not a real Instagram base64 shortcode.","triggerScenarios":"The /p/<code>/ path contains an empty, truncated, or corrupted shortcode (e.g. shell-escaped characters, %XX sequences left in, a typo'd code).","commonSituations":"Escaping the URL in shell so % or backslashes remain in the shortcode; manually typing the shortcode with mistakes; truncated copies from logs.","solutions":["Copy the link directly from the post's Share > Copy Link and paste unmodified","Remove any shell escaping/backslashes from the shortcode","Verify the shortcode only contains expected base64 URL characters (letters, digits, - and _)"],"exampleFix":"// before\nigdl 'https://www.instagram.com/p/Cxyz\\\\123/'\n// after\nigdl 'https://www.instagram.com/p/Cxyz123/'","handlingStrategy":"validation","validationCode":"const m = raw.match(/\\/(?:p|reel|tv)\\/([^/?#]+)/);\nconst shortcode = m && m[1];\nif (!shortcode || !/^[A-Za-z0-9_-]+$/.test(shortcode)) throw new Error('Invalid shortcode; copy the link unmodified from the post');","typeGuard":"function hasValidShortcode(v) {\n  const m = String(v).match(/\\/(?:p|reel|tv)\\/([^/?#]+)/);\n  return !!m && /^[A-Za-z0-9_-]+$/.test(m[1]);\n}","tryCatchPattern":"try {\n  await igDownload(raw);\n} catch (e) {\n  if (e.name === 'ArgumentError' && /Invalid Instagram shortcode/.test(e.message)) {\n    console.error('Re-copy the link via Share > Copy Link; remove shell escapes.');\n  } else throw e;\n}","preventionTips":["Paste links without manual editing or re-typing","Avoid backslash/percent escaping in shells","Verify the shortcode contains only [A-Za-z0-9_-]"],"tags":["cli","shortcode","argument-validation"],"backgroundTag":"invalid-shortcode","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}