jackwener/OpenCLI · error · ArgumentError

Invalid IMDb ID: "${input}"

Error message

Invalid IMDb ID: "${input}"

What it means

Thrown by normalizeImdbId when the user-supplied input is neither a valid IMDb ID with the expected prefix (tt or nm) nor an IMDb title/name URL. It accepts IDs like tt1375666/nm0634240 or full URLs and normalizes them; anything else raises ArgumentError.

Source

Thrown at clis/imdb/utils.js:17

import { ArgumentError } from '@jackwener/opencli/errors';
/**
 * Normalize an IMDb title or person input to a bare ID.
 * Accepts bare IDs, desktop URLs, mobile URLs, and URLs with language prefixes or query params.
 */
export function normalizeImdbId(input, prefix) {
    const trimmed = input.trim();
    const barePattern = new RegExp(`^${prefix}\\d{7,8}$`);
    if (barePattern.test(trimmed)) {
        return trimmed;
    }
    const pathPattern = new RegExp(`/(?:[a-z]{2}/)?(?:title|name)/(${prefix}\\d{7,8})(?:[/?#]|$)`, 'i');
    const pathMatch = trimmed.match(pathPattern);
    if (pathMatch) {
        return pathMatch[1];
    }
    throw new ArgumentError(`Invalid IMDb ID: "${input}"`, `Expected ${prefix === 'tt' ? 'title' : 'name'} ID like ${prefix === 'tt' ? 'tt1375666' : 'nm0634240'} or an IMDb URL`);
}
/**
 * Convert an ISO 8601 duration string to a short human-readable format for table display.
 * Example: PT2H28M -> 2h 28m.
 */
export function formatDuration(iso) {
    if (!iso) {
        return '';
    }
    const match = iso.match(/^PT(?:(\d+)H)?(?:(\d+)M)?$/);
    if (!match) {
        return '';
    }
    const parts = [];
    if (match[1]) {
        parts.push(`${match[1]}h`);
    }
    if (match[2]) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use the full canonical ID including prefix, e.g. tt1375666 or nm0634240
  2. Ensure the prefix matches the expected type: tt for titles, nm for names
  3. Pass an IMDb URL of the form https://www.imdb.com/title/tt1375666/ instead of a bare ID
  4. Trim whitespace and remove HTML tags/quotes from clipboard-pasted input
  5. Check you are not passing a search or list URL; navigate to the actual title/name page and copy its URL

Example fix

// before
await imdb.id('1375666');
// after
await imdb.id('tt1375666');
Defensive patterns

Strategy: validation

Validate before calling

function isValidImdbId(input, prefix) {
  const re = new RegExp(`^${prefix}\\d{7,8}$`);
  return re.test(input.trim());
}
// call only if isValidImdbId(id, 'tt') || /^(title|name)\//.test(urlPath)

Type guard

const isImdbId = (v) => typeof v === 'string' && /^(tt|nm)\d{7,8}$/.test(v.trim());

Try / catch

try {
  return await imdb.id(raw);
} catch (e) {
  if (e instanceof ArgumentError || /Invalid IMDb ID/.test(e.message)) {
    throw new Error(`Use a full IMDb ID like tt1375666 or a title/name URL; got "${raw}"`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling the id command (or any caller of normalizeImdbId) with a string that does not match /^[a-z]{2}\/)?(?:title|name)\/(tt|nm)\d{7,8}/ URL pattern or the ${prefix}\d{7,8} ID format.

Common situations: Passing a bare numeric ID (1375666) without the tt/nm prefix; passing the wrong prefix type (nm ID where a tt is expected); pasting a search-results URL instead of a title/name URL; typos or extra whitespace/HTML in the ID; IMDb IDs with fewer than 7 digits (legacy).

Related errors


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