jackwener/OpenCLI · error · ArgumentError
youtube history limit must be <= ${MAX_LIMIT}
Error message
youtube history limit must be <= ${MAX_LIMIT} What it means
ArgumentError thrown by normalizeLimit when the `limit` argument exceeds MAX_LIMIT (200) for `youtube history`. The library caps pagination to at most 200 videos to bound scraping time (up to 20 pages of requests). Values must be integers in [1, 200].
Source
Thrown at clis/youtube/history.js:29
} from '@jackwener/opencli/errors';
import {
prepareYoutubeApiPage,
readYoutubeSapisid,
SAPISID_HASH_FN,
} from './utils.js';
const DEFAULT_LIMIT = 30;
const MAX_LIMIT = 200;
const MAX_PAGES = 20;
const REQUEST_TIMEOUT_SECONDS = 15;
function normalizeLimit(value) {
const limit = Number(value ?? DEFAULT_LIMIT);
if (!Number.isInteger(limit) || limit <= 0) {
throw new ArgumentError('youtube history limit must be a positive integer');
}
if (limit > MAX_LIMIT) {
throw new ArgumentError(`youtube history limit must be <= ${MAX_LIMIT}`);
}
return limit;
}
cli({
site: 'youtube',
name: 'history',
access: 'read',
description: 'Get YouTube watch history',
domain: 'www.youtube.com',
strategy: Strategy.COOKIE,
args: [
{ name: 'limit', type: 'int', default: DEFAULT_LIMIT, help: 'Max videos to return (default 30, max 200)' },
],
columns: ['rank', 'title', 'channel', 'views', 'duration', 'url'],
func: async (page, kwargs) => {
const limit = normalizeLimit(kwargs.limit);
await prepareYoutubeApiPage(page);View on GitHub (pinned to 49907e53dc)
Solutions
- Reduce limit to 200 or below.
- Clamp programmatically: Math.min(Math.max(1, n), 200).
- If more history is genuinely needed, call the command multiple times with pagination if supported.
- Check the command's help text for the documented maximum.
Example fix
// before
await yt.history({ limit: 1000 }); // ArgumentError: must be <= 200
// after
const n = Math.min(Math.max(1, Number(reqLimit) || 30), 200);
await yt.history({ limit: n }); Defensive patterns
Strategy: validation
Validate before calling
const MAX = 200;
function clampLimit(v) {
const n = Number(v);
if (!Number.isInteger(n) || n <= 0) return 30;
return Math.min(n, MAX);
}
opts.limit = clampLimit(opts.limit); Type guard
function withinCap(v) {
return typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 200;
} Try / catch
try {
return await yt.history({ limit });
} catch (e) {
if (e instanceof ArgumentError && /<= 200/.test(e.message)) {
return yt.history({ limit: 200 });
}
throw e;
} Prevention
- Clamp user/config limits to 200 before calling.
- Read the command help for the documented maximum.
- Never pass unbounded page counts from generic pagination loops.
- Centralize limit normalization in one helper.
When it happens
Trigger: Calling `youtube history` with limit > 200 — e.g. --limit 500 or programmatic limit: 1000. The check runs after the positive-integer check, so 201+ valid integers trigger this exact branch.
Common situations: Users expecting unlimited history and asking for thousands of items; copying limits from other tools with higher caps; programmatically computing a limit without clamping to the documented max.
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
- homebrew ${label} must be <= ${maxValue}
- medium limit must be <= ${maxValue}
- limit must be <= 100
- youtube history limit must be a positive integer
- ${label} must be <= ${maxValue}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/136402bbcee45459.
Report an issue: GitHub.