jackwener/OpenCLI · error · ArgumentError
Invalid Instagram shortcode: ${shortcode}
Error message
Invalid Instagram shortcode: ${shortcode} What it means
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.
Source
Thrown at clis/instagram/download.js:77
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];
}
if (!kind || !shortcode) {
throw new ArgumentError(`Unsupported Instagram media URL: ${raw}`, 'Only /p/<shortcode>/, /reel/<shortcode>/, and /tv/<shortcode>/ links are supported');
}
if (!shortcodeToMediaId(shortcode)) {
throw new ArgumentError(`Invalid Instagram shortcode: ${shortcode}`, 'Copy the link straight from the post, without escaping it');
}
return {
kind: kind,
shortcode,
canonicalUrl: `https://www.instagram.com/${kind}/${shortcode}/`,
};
}
export function buildInstagramDownloadItems(shortcode, items) {
if (!Array.isArray(items)) {
throw new CommandExecutionError('Instagram media metadata returned a malformed media list');
}
return items.map((item, index) => {
if (!item || typeof item !== 'object' || !['image', 'video'].includes(item.type)) {
throw new CommandExecutionError(`Instagram media metadata returned malformed media item #${index + 1}`);
}
let downloadUrl;
try {
downloadUrl = new URL(String(item.url || ''));View on GitHub (pinned to 49907e53dc)
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 _)
Example fix
// before igdl 'https://www.instagram.com/p/Cxyz\\123/' // after igdl 'https://www.instagram.com/p/Cxyz123/'
Defensive patterns
Strategy: validation
Validate before calling
const m = raw.match(/\/(?:p|reel|tv)\/([^/?#]+)/);
const shortcode = m && m[1];
if (!shortcode || !/^[A-Za-z0-9_-]+$/.test(shortcode)) throw new Error('Invalid shortcode; copy the link unmodified from the post'); Type guard
function hasValidShortcode(v) {
const m = String(v).match(/\/(?:p|reel|tv)\/([^/?#]+)/);
return !!m && /^[A-Za-z0-9_-]+$/.test(m[1]);
} Try / catch
try {
await igDownload(raw);
} catch (e) {
if (e.name === 'ArgumentError' && /Invalid Instagram shortcode/.test(e.message)) {
console.error('Re-copy the link via Share > Copy Link; remove shell escapes.');
} else throw e;
} Prevention
- Paste links without manual editing or re-typing
- Avoid backslash/percent escaping in shells
- Verify the shortcode contains only [A-Za-z0-9_-]
When it happens
Trigger: The /p/<code>/ path contains an empty, truncated, or corrupted shortcode (e.g. shell-escaped characters, %XX sequences left in, a typo'd code).
Common situations: Escaping the URL in shell so % or backslashes remain in the shortcode; manually typing the shortcode with mistakes; truncated copies from logs.
Related errors
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
- --to station must not be empty
- --seat-types must contain only 12306 seat letters/digits (A-
- --from and --to must differ; both resolved to ${fromStation.
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/2c7b61d5b45d95c1.
Report an issue: GitHub.