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
- Use the full canonical ID including prefix, e.g. tt1375666 or nm0634240
- Ensure the prefix matches the expected type: tt for titles, nm for names
- Pass an IMDb URL of the form https://www.imdb.com/title/tt1375666/ instead of a bare ID
- Trim whitespace and remove HTML tags/quotes from clipboard-pasted input
- 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
- Always store/copy full IDs including the tt/nm prefix
- Match prefix to entity type: tt for titles, nm for names
- Trim and sanitize clipboard input before passing
- Copy URLs from the actual title/name page, not search results
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
- bbc topic "${args.topic}" is not supported
- bbc ${label} must be a positive integer
- bbc ${label} must be <= ${maxValue}
- ARGUMENT
- ${label} must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/27d3aebd0e53f571.
Report an issue: GitHub.