jackwener/OpenCLI · error · ArgumentError

Invalid Instagram URL: ${raw}

Error message

Invalid Instagram URL: ${raw}

What it means

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>/.

Source

Thrown at clis/instagram/download.js:53

        const digit = INSTAGRAM_SHORTCODE_ALPHABET.indexOf(character);
        if (digit < 0) return '';
        mediaId = mediaId * 64n + BigInt(digit);
        if (mediaId > MAX_INSTAGRAM_MEDIA_ID) return '';
    }
    if (mediaId <= 0n) return '';
    return mediaId.toString();
}
export function parseInstagramMediaTarget(input) {
    const raw = String(input || '').trim();
    if (!raw) {
        throw new ArgumentError('Instagram URL is required', 'Expected https://www.instagram.com/p/... or https://www.instagram.com/reel/...');
    }
    let url;
    try {
        url = new URL(raw);
    }
    catch {
        throw new ArgumentError(`Invalid Instagram URL: ${raw}`, 'Expected https://www.instagram.com/p/<shortcode>/ or /reel/<shortcode>/');
    }
    if (!['http:', 'https:'].includes(url.protocol)) {
        throw new ArgumentError(`Unsupported URL protocol: ${url.protocol}`);
    }
    const host = url.hostname.toLowerCase();
    if (host !== INSTAGRAM_HOST_SUFFIX && !host.endsWith(`.${INSTAGRAM_HOST_SUFFIX}`)) {
        throw new ArgumentError(`Unsupported host: ${host}`, 'Only instagram.com URLs are supported');
    }
    const segments = url.pathname.split('/').filter(Boolean);
    let kind;
    let shortcode;
    if (segments.length >= 2 && SUPPORTED_KINDS.has(segments[0])) {
        kind = segments[0];
        shortcode = segments[1];
    }
    else if (segments.length >= 3 && SUPPORTED_KINDS.has(segments[1])) {
        kind = segments[1];
        shortcode = segments[2];

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass the full post URL, e.g. https://www.instagram.com/p/<shortcode>/, quoted for your shell
  2. Trim whitespace and URL-encode stray characters in the input before calling
  3. Check where the value comes from (env var/config/clipboard) and fix the source of the empty or partial string

Example fix

// before
igdl Cxyz123
// after
igdl 'https://www.instagram.com/p/Cxyz123/'
Defensive patterns

Strategy: validation

Validate before calling

function isValidInstagramUrl(raw) {
  try { const u = new URL(raw); return ['http:','https:'].includes(u.protocol) && u.hostname.toLowerCase().endsWith('instagram.com'); }
  catch { return false; }
}
if (!isValidInstagramUrl(raw)) throw new Error('Provide a full https://www.instagram.com/p/<shortcode>/ link');

Type guard

function isInstagramUrl(v) {
  if (typeof v !== 'string' || v.length === 0) return false;
  try { const u = new URL(v); return (u.protocol === 'http:' || u.protocol === 'https:') && (u.hostname === 'instagram.com' || u.hostname.endsWith('.instagram.com')); }
  catch { return false; }
}

Try / catch

try {
  await igDownload(raw);
} catch (e) {
  if (e.name === 'ArgumentError' && /Invalid Instagram URL/.test(e.message)) {
    console.error('Please pass the full post URL, e.g. https://www.instagram.com/p/<shortcode>/');
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/922941d57ce6e85f. Report an issue: GitHub.