jackwener/OpenCLI · error · ArgumentError

limit must be <= ${MAX_LIMIT}

Error message

limit must be <= ${MAX_LIMIT}

What it means

normalizeLimit also caps --limit at MAX_LIMIT (50) and throws an ArgumentError when a valid positive integer exceeds the cap, with an example suggesting --limit 50. This keeps scraping requests bounded so the command doesn't over-fetch or hammer the page.

Source

Thrown at clis/aibase/news.js:15

import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, EmptyResultError, getErrorMessage } from '@jackwener/opencli/errors';

const AIBASE_DAILY_URL = 'https://www.aibase.com/zh/daily';
const DEFAULT_LIMIT = 20;
const MAX_LIMIT = 50;

function normalizeLimit(value) {
    const raw = value ?? DEFAULT_LIMIT;
    const limit = Number(raw);
    if (!Number.isInteger(limit) || limit <= 0) {
        throw new ArgumentError('limit must be a positive integer', `Example: opencli aibase news --limit ${DEFAULT_LIMIT}`);
    }
    if (limit > MAX_LIMIT) {
        throw new ArgumentError(`limit must be <= ${MAX_LIMIT}`, `Example: opencli aibase news --limit ${MAX_LIMIT}`);
    }
    return limit;
}

function normalizeText(value) {
    return String(value ?? '').replace(/\s+/g, ' ').trim();
}

function buildExtractAibaseNewsJs() {
    return `
      (() => {
        const anchors = Array.from(document.querySelectorAll('.bg-white .grid a[href], a[href*="/zh/daily/"]'))
          .filter((anchor) => {
            const href = anchor.getAttribute('href') || '';
            const text = (anchor.innerText || anchor.textContent || '').trim();
            return text && href && !href.endsWith('/zh/daily') && !href.endsWith('/zh/daily/');
          });
        if (anchors.length === 0) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use --limit 50 (the maximum) instead.
  2. Omit --limit (default 20) if fewer items suffice.
  3. Note the daily page only exposes a bounded set of articles anyway; there are rarely more than 50 rows to return.

Example fix

// before
opencli aibase news --limit 100
// after
opencli aibase news --limit 50
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(limitArg);
if (Number.isInteger(n) && n > 50) throw new Error('--limit max is 50');

Type guard

function isWithinCap(v, cap = 50) {
  return typeof v === 'number' && Number.isInteger(v) && v > 0 && v <= cap;
}

Try / catch

try {
  await runCommand(['aibase', 'news', '--limit', String(n)]);
} catch (e) {
  if (e instanceof ArgumentError && e.message.startsWith('limit must be <=')) {
    await runCommand(['aibase', 'news', '--limit', '50']);
  } else throw e;
}

Prevention

When it happens

Trigger: Running `opencli aibase news --limit 51` or higher (e.g. --limit 100, --limit 1000).

Common situations: Users wanting 'all' items passing a large number, scripts using a generic page-size (100) that exceeds this command's max, and confusion with other commands whose limits are uncapped.

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/a91d5086c85da777. Report an issue: GitHub.