jackwener/OpenCLI · error · ArgumentError
youtube search limit must be <= ${MAX_LIMIT}
Error message
youtube search limit must be <= ${MAX_LIMIT} What it means
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.
Source
Thrown at clis/youtube/search.js:53
views: 'CAM%3D',
rating: 'CAE%3D',
};
function normalizeChoice(value, choices, label) {
const normalized = String(value || '').trim();
if (normalized && !Object.hasOwn(choices, normalized)) {
throw new ArgumentError(`youtube search ${label} must be one of: ${Object.keys(choices).join(', ')}`);
}
return normalized;
}
function normalizeLimit(value) {
const limit = Number(value ?? DEFAULT_LIMIT);
if (!Number.isInteger(limit) || limit <= 0) {
throw new ArgumentError('youtube search limit must be a positive integer');
}
if (limit > MAX_LIMIT) {
throw new ArgumentError(`youtube search limit must be <= ${MAX_LIMIT}`);
}
return limit;
}
cli({
site: 'youtube',
name: 'search',
access: 'read',
description: 'Search YouTube videos, Shorts, channels, and playlists',
domain: 'www.youtube.com',
strategy: Strategy.COOKIE,
args: [
{ name: 'query', required: true, positional: true, help: 'Search query' },
{ name: 'limit', type: 'int', default: DEFAULT_LIMIT, help: 'Max results (max 50)' },
{ name: 'type', default: '', help: 'Filter type: shorts, video, channel, playlist' },
{ name: 'upload', default: '', help: 'Upload date: hour, today, week, month, year' },
{ name: 'sort', default: '', help: 'Sort by: relevance, date, views, rating' },
],View on GitHub (pinned to 49907e53dc)
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
Example fix
// before opencli youtube search "cats" --limit 500 // after opencli youtube search "cats" --limit 50
Defensive patterns
Strategy: validation
Validate before calling
function clampLimit(value, { MAX = 50 } = {}) {
const n = Math.floor(Number(value));
if (!Number.isFinite(n)) return null; // omit flag -> default 20
return Math.min(Math.max(1, n), MAX);
}
// usage: --limit clampLimit(requested) ?? undefined Type guard
const isWithinLimitCap = (v, cap = 50) => Number.isInteger(Number(v)) && Number(v) > 0 && Number(v) <= cap;
Try / catch
try {
await run('youtube search', [query, '--limit', String(limit)]);
} catch (e) {
if (/limit must be <=/i.test(e.message)) {
console.warn(`--limit ${limit} exceeds cap 50; retrying with 50`);
return run('youtube search', [query, '--limit', '50']);
}
throw e;
} Prevention
- 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
When it happens
Trigger: `--limit 100`, `--limit 1000`, or a script computing a large page size and passing it unclamped to youtube search.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- youtube search ${label} must be one of: ${Object.keys(choice
- youtube search limit must be a positive integer
- --${name} must be between ${min} and ${max}, got ${parsed}
- juejin ${label} must be <= ${maxValue}
- --limit must be an integer between 1 and 500
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/fc315ca179b756f0.
Report an issue: GitHub.