jackwener/OpenCLI · error · ArgumentError

coingecko derivatives limit must be a positive integer

Error message

coingecko derivatives limit must be a positive integer

What it means

This ArgumentError is thrown by the coingecko derivatives command's `func` when the `limit` argument, after coercion via Number(args.limit ?? 20), is not an integer or is <= 0. It guards the query parameter sent to the CoinGecko /derivatives endpoint so the API only receives a sensible page size. It fires before any network request is made.

Source

Thrown at clis/coingecko/derivatives.js:30

const ENDPOINT = 'https://api.coingecko.com/api/v3/derivatives';

cli({
    site: 'coingecko',
    name: 'derivatives',
    access: 'read',
    description: 'Top crypto derivative (perpetual / futures) markets by 24h volume',
    domain: 'api.coingecko.com',
    strategy: Strategy.PUBLIC,
    browser: false,
    args: [
        { name: 'limit', type: 'int', default: 20, help: 'Max rows to return (1-500; CoinGecko returns one large page).' },
        { name: 'symbol', type: 'string', required: false, help: 'Optional symbol substring filter (e.g. "BTC", "ETHUSDT").' },
    ],
    columns: ['rank', 'market', 'symbol', 'indexId', 'contractType', 'price', 'change24hPct', 'fundingRate', 'openInterestUsd', 'volume24hUsd', 'expired'],
    func: async (args) => {
        const limit = Number(args.limit ?? 20);
        if (!Number.isInteger(limit) || limit <= 0) {
            throw new ArgumentError('coingecko derivatives limit must be a positive integer');
        }
        if (limit > 500) {
            throw new ArgumentError('coingecko derivatives limit must be <= 500');
        }
        const filter = args.symbol == null ? '' : String(args.symbol).trim().toUpperCase();
        let resp;
        try {
            resp = await fetch(ENDPOINT, { headers: { 'User-Agent': 'Mozilla/5.0' } });
        }
        catch (err) {
            throw new CommandExecutionError(`coingecko derivatives request failed: ${err?.message ?? err}`);
        }
        if (resp.status === 429) {
            throw new CommandExecutionError(
                'coingecko derivatives returned HTTP 429 (rate limited)',
                'Free tier allows ~30 calls/min. Wait and retry.',
            );
        }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer limit >= 1, e.g. --limit 20
  2. Omit the --limit flag entirely to use the default of 20
  3. If the value comes from config/script input, validate it is a positive integer before invoking

Example fix

// before
cli derivatives --limit 0
// after
cli derivatives --limit 20
Defensive patterns

Strategy: validation

Validate before calling

function isValidLimit(v) {
  const n = Number(v ?? 20);
  return Number.isInteger(n) && n > 0;
}
if (!isValidLimit(args.limit)) throw new Error('limit must be a positive integer');

Type guard

const isPositiveInt = (v) => typeof v === 'number' && Number.isInteger(v) && v > 0;

Prevention

When it happens

Trigger: Calling the derivatives command with --limit set to a non-integer (e.g. 'abc', '2.5'), zero, or a negative number; passing an empty string that coerces to NaN.

Common situations: Typo'd CLI flag values, shell variables expanding to empty strings, scripts passing a float from computed values, users assuming a 0 or -1 limit means 'unlimited'.

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/6a4fa3533d9bb38f. Report an issue: GitHub.