jackwener/OpenCLI · error · ArgumentError
limit must be <= 250 (CoinGecko per_page upper bound)
Error message
limit must be <= 250 (CoinGecko per_page upper bound)
What it means
This ArgumentError is thrown when the requested limit exceeds 250, the maximum per_page value CoinGecko's /coins/markets endpoint accepts. The check runs before the HTTP request so no doomed call is made. To fetch more than 250 coins you must paginate with the page parameter.
Source
Thrown at clis/coingecko/top.js:25
name: 'top',
access: 'read',
description: '按市值排序的加密货币行情(默认 USD)',
domain: 'api.coingecko.com',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'currency', type: 'string', default: 'usd', help: '计价币种 (usd / cny / eur / jpy ...)' },
{ name: 'limit', type: 'int', default: 10, help: '返回数量(默认 10,最多 250)' },
],
columns: ['rank', 'symbol', 'name', 'price', 'change24hPct', 'marketCap', 'volume24h', 'high24h', 'low24h'],
func: async (args) => {
const currency = String(args.currency ?? 'usd').toLowerCase();
const limit = Number(args.limit ?? 10);
if (!Number.isInteger(limit) || limit <= 0) {
throw new ArgumentError('limit must be a positive integer');
}
if (limit > 250) {
throw new ArgumentError('limit must be <= 250 (CoinGecko per_page upper bound)');
}
const url = new URL('https://api.coingecko.com/api/v3/coins/markets');
url.searchParams.set('vs_currency', currency);
url.searchParams.set('order', 'market_cap_desc');
url.searchParams.set('per_page', String(limit));
url.searchParams.set('page', '1');
url.searchParams.set('sparkline', 'false');
let resp;
try {
resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });
} catch (error) {
throw new CommandExecutionError(`coingecko top request failed: ${error?.message || error}`);
}
if (!resp.ok) throw new CommandExecutionError(`coingecko top failed: HTTP ${resp.status}`);
let data;
try {View on GitHub (pinned to 49907e53dc)
Solutions
- Set limit to at most 250 for a single request.
- Use the API's pagination: request per_page=250 with page=1,2,3... and merge results for more coins.
- Clamp in your caller: limit = Math.min(Math.max(1, n), 250).
- If you truly need the whole market, loop pages until an empty array is returned.
Example fix
// before
await runCli('coingecko', 'top', ['--limit', '500']);
// after
const limit = Math.min(Math.max(1, Number(raw)), 250);
await runCli('coingecko', 'top', ['--limit', String(limit)]); Defensive patterns
Strategy: validation
Validate before calling
const n = Number(rawLimit ?? 10);
if (!Number.isInteger(n) || n < 1 || n > 250) throw new Error(`limit must be 1..250, got ${rawLimit}`); Type guard
function isValidLimit(v) { return Number.isInteger(v) && v >= 1 && v <= 250; } Try / catch
try {
rows = await runCli('coingecko', 'top', ['--limit', limit]);
} catch (e) {
if (/limit must be <= 250/.test(e.message)) {
console.warn('Clamping limit to 250; paginate for more');
rows = await runCli('coingecko', 'top', ['--limit', '250']);
} else throw e;
} Prevention
- Clamp with Math.min(Math.max(1, n), 250) before calling
- Remember CoinGecko caps per_page at 250 — paginate with page for more
- Validate dashboard/config coin counts against the 250 cap
- Document the 250 max wherever users configure limits
When it happens
Trigger: --limit 500, --limit 1000, or a config value like 'top 500 coins' passed straight through; Number coercion of a large count from a dashboard config.
Common situations: Users expecting the CLI to auto-paginate past 250; scripts copying a coin list length (>250) as the limit; misunderstanding that per_page is capped by the API, not the CLI.
Related errors
- limit must be an integer between 1 and ${max}
- npm ${label} must be a positive integer
- npm ${label} must be <= ${maxValue}
- ${name} must be <= ${max}
- Qianwen history page_size must be an integer between 1 and 1
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/d4a9dd04aadacea7.
Report an issue: GitHub.