jackwener/OpenCLI · error · ArgumentError

rest-countries ${label} must be <= ${maxValue}

Error message

rest-countries ${label} must be <= ${maxValue}

What it means

requireBoundedInt throws ArgumentError when the parsed integer exceeds the command's allowed maximum for the labeled option. Each command sets its own cap (e.g. country allows up to 250, region is capped at exactly 250). The error names both the label and the maxValue so the caller knows the exact ceiling.

Source

Thrown at clis/rest-countries/utils.js:35

    'name', 'cca2', 'cca3', 'ccn3', 'capital', 'region', 'subregion',
    'population', 'area', 'languages', 'currencies', 'flag', 'latlng', 'timezones',
    'independent', 'unMember', 'landlocked',
].join(',');

export function requireString(value, label) {
    const s = String(value ?? '').trim();
    if (!s) throw new ArgumentError(`rest-countries ${label} cannot be empty`);
    return s;
}

export function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {
    const raw = value ?? defaultValue;
    const n = typeof raw === 'number' ? raw : Number(raw);
    if (!Number.isInteger(n) || n <= 0) {
        throw new ArgumentError(`rest-countries ${label} must be a positive integer`);
    }
    if (n > maxValue) {
        throw new ArgumentError(`rest-countries ${label} must be <= ${maxValue}`);
    }
    return n;
}

export function requireRegion(value) {
    const raw = String(value ?? '').trim().toLowerCase();
    if (!raw) throw new ArgumentError('rest-countries region is required (e.g. "europe", "asia")');
    if (!REST_COUNTRIES_REGIONS.has(raw)) {
        throw new ArgumentError(
            `rest-countries region "${value}" is not recognised`,
            `Allowed regions: ${[...REST_COUNTRIES_REGIONS].join(', ')}.`,
        );
    }
    return raw;
}

export async function restCountriesFetch(url, label) {
    let resp;

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Lower limit to the command's max (25 for country, 250 for region).
  2. Read the command docs/CLI help for the supported limit range.
  3. Paginate manually if you need more results than the cap.
  4. Clamp the value with Math.min before calling.

Example fix

// before
await countryCommand({ name: 'a', limit: 1000 });
// after
await countryCommand({ name: 'a', limit: Math.min(userLimit, 250) });
Defensive patterns

Strategy: validation

Validate before calling

const MAX = { country: 25, region: 250 };
if (limit > MAX[command]) {
  limit = MAX[command]; // clamp instead of failing
}

Type guard

function isWithinLimit(n, max) { return Number.isInteger(n) && n > 0 && n <= max; }

Try / catch

try {
  await countryCommand({ name, limit });
} catch (err) {
  if (err instanceof ArgumentError && /must be <=/.test(err.message)) {
    const max = Number(err.message.match(/<= (\d+)/)?.[1] ?? 25);
    return countryCommand({ name, limit: max });
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling the rest-countries country command with limit > 25 (e.g. 100), or region with limit > 250, tripping `if (n > maxValue)` at clis/rest-countries/utils.js:35.

Common situations: Assuming the API allows unlimited results; copying a limit from another command with a higher cap; tuning scripts requesting very large pages.

Related errors


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