{"record":{"id":"fc315ca179b756f0","repo":"jackwener/OpenCLI","slug":"youtube-search-limit-must-be-max-limit","errorCode":null,"errorMessage":"youtube search limit must be <= ${MAX_LIMIT}","messagePattern":"youtube search limit must be <= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/youtube/search.js","lineNumber":53,"sourceCode":"    views: 'CAM%3D',\n    rating: 'CAE%3D',\n};\n\nfunction normalizeChoice(value, choices, label) {\n    const normalized = String(value || '').trim();\n    if (normalized && !Object.hasOwn(choices, normalized)) {\n        throw new ArgumentError(`youtube search ${label} must be one of: ${Object.keys(choices).join(', ')}`);\n    }\n    return normalized;\n}\n\nfunction normalizeLimit(value) {\n    const limit = Number(value ?? DEFAULT_LIMIT);\n    if (!Number.isInteger(limit) || limit <= 0) {\n        throw new ArgumentError('youtube search limit must be a positive integer');\n    }\n    if (limit > MAX_LIMIT) {\n        throw new ArgumentError(`youtube search limit must be <= ${MAX_LIMIT}`);\n    }\n    return limit;\n}\n\ncli({\n    site: 'youtube',\n    name: 'search',\n    access: 'read',\n    description: 'Search YouTube videos, Shorts, channels, and playlists',\n    domain: 'www.youtube.com',\n    strategy: Strategy.COOKIE,\n    args: [\n        { name: 'query', required: true, positional: true, help: 'Search query' },\n        { name: 'limit', type: 'int', default: DEFAULT_LIMIT, help: 'Max results (max 50)' },\n        { name: 'type', default: '', help: 'Filter type: shorts, video, channel, playlist' },\n        { name: 'upload', default: '', help: 'Upload date: hour, today, week, month, year' },\n        { name: 'sort', default: '', help: 'Sort by: relevance, date, views, rating' },\n    ],","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/youtube/search.js#L35-L71","documentation":"ArgumentError from normalizeLimit enforcing MAX_LIMIT = 50. Values above 50 are rejected because YouTube search continuations are capped and the CLI will not silently clamp; you must request at most 50 results per invocation.","triggerScenarios":"`--limit 100`, `--limit 1000`, or a script computing a large page size and passing it unclamped to youtube search.","commonSituations":"Assuming the CLI paginates automatically like the API, porting scripts from other tools with higher caps, or passing total dataset sizes instead of per-call limits.","solutions":["Cap the value at 50: --limit 50 (the CLI fetches up to MAX_PAGES internally within that cap)","Clamp in code before calling: Math.min(Math.max(1, n), 50)","Split large needs across multiple targeted queries instead of one huge limit"],"exampleFix":"// before\nopencli youtube search \"cats\" --limit 500\n// after\nopencli youtube search \"cats\" --limit 50","handlingStrategy":"validation","validationCode":"function clampLimit(value, { MAX = 50 } = {}) {\n  const n = Math.floor(Number(value));\n  if (!Number.isFinite(n)) return null; // omit flag -> default 20\n  return Math.min(Math.max(1, n), MAX);\n}\n// usage: --limit clampLimit(requested) ?? undefined","typeGuard":"const isWithinLimitCap = (v, cap = 50) => Number.isInteger(Number(v)) && Number(v) > 0 && Number(v) <= cap;","tryCatchPattern":"try {\n  await run('youtube search', [query, '--limit', String(limit)]);\n} catch (e) {\n  if (/limit must be <=/i.test(e.message)) {\n    console.warn(`--limit ${limit} exceeds cap 50; retrying with 50`);\n    return run('youtube search', [query, '--limit', '50']);\n  }\n  throw e;\n}","preventionTips":["Never request more than 50 per call — the CLI will not auto-clamp","Clamp or split large result needs before invoking","Remember the CLI already paginates continuations within the 50 cap","For >50 results, run multiple targeted queries instead of one huge limit"],"tags":["youtube","search","argument-validation","cli","limit"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}