{"record":{"id":"27d3aebd0e53f571","repo":"jackwener/OpenCLI","slug":"invalid-imdb-id-input","errorCode":null,"errorMessage":"Invalid IMDb ID: \"${input}\"","messagePattern":"Invalid IMDb ID: \"(.+?)\"","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/imdb/utils.js","lineNumber":17,"sourceCode":"import { ArgumentError } from '@jackwener/opencli/errors';\n/**\n * Normalize an IMDb title or person input to a bare ID.\n * Accepts bare IDs, desktop URLs, mobile URLs, and URLs with language prefixes or query params.\n */\nexport function normalizeImdbId(input, prefix) {\n    const trimmed = input.trim();\n    const barePattern = new RegExp(`^${prefix}\\\\d{7,8}$`);\n    if (barePattern.test(trimmed)) {\n        return trimmed;\n    }\n    const pathPattern = new RegExp(`/(?:[a-z]{2}/)?(?:title|name)/(${prefix}\\\\d{7,8})(?:[/?#]|$)`, 'i');\n    const pathMatch = trimmed.match(pathPattern);\n    if (pathMatch) {\n        return pathMatch[1];\n    }\n    throw new ArgumentError(`Invalid IMDb ID: \"${input}\"`, `Expected ${prefix === 'tt' ? 'title' : 'name'} ID like ${prefix === 'tt' ? 'tt1375666' : 'nm0634240'} or an IMDb URL`);\n}\n/**\n * Convert an ISO 8601 duration string to a short human-readable format for table display.\n * Example: PT2H28M -> 2h 28m.\n */\nexport function formatDuration(iso) {\n    if (!iso) {\n        return '';\n    }\n    const match = iso.match(/^PT(?:(\\d+)H)?(?:(\\d+)M)?$/);\n    if (!match) {\n        return '';\n    }\n    const parts = [];\n    if (match[1]) {\n        parts.push(`${match[1]}h`);\n    }\n    if (match[2]) {","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/imdb/utils.js#L1-L35","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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"],"exampleFix":"// before\nawait imdb.id('1375666');\n// after\nawait imdb.id('tt1375666');","handlingStrategy":"validation","validationCode":"function isValidImdbId(input, prefix) {\n  const re = new RegExp(`^${prefix}\\\\d{7,8}$`);\n  return re.test(input.trim());\n}\n// call only if isValidImdbId(id, 'tt') || /^(title|name)\\//.test(urlPath)","typeGuard":"const isImdbId = (v) => typeof v === 'string' && /^(tt|nm)\\d{7,8}$/.test(v.trim());","tryCatchPattern":"try {\n  return await imdb.id(raw);\n} catch (e) {\n  if (e instanceof ArgumentError || /Invalid IMDb ID/.test(e.message)) {\n    throw new Error(`Use a full IMDb ID like tt1375666 or a title/name URL; got \"${raw}\"`);\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["validation","argument","imdb-id","input-parsing"],"backgroundTag":"invalid-identifier-format","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}