jackwener/OpenCLI · error · ArgumentError

huodongxing limit must be <= ${MAX_LIMIT}

Error message

huodongxing limit must be <= ${MAX_LIMIT}

What it means

requireLimit caps the huodongxing events `limit` at MAX_LIMIT = 50 (defined in clis/huodongxing/events.js:5). Values above the cap — including valid integers like 51, 100, 1000 — throw this ArgumentError naming the maximum. The cap protects the underlying page scrape from requesting impractically large result sets.

Source

Thrown at clis/huodongxing/events.js:30

  'eventType',
  'city',
  'location',
  'organizer',
  'url',
];

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

export function requireLimit(value) {
  const raw = value ?? 20;
  const limit = typeof raw === 'number' ? raw : Number(String(raw).trim());
  if (!Number.isInteger(limit) || limit <= 0) {
    throw new ArgumentError('huodongxing limit must be a positive integer');
  }
  if (limit > MAX_LIMIT) {
    throw new ArgumentError(`huodongxing limit must be <= ${MAX_LIMIT}`);
  }
  return limit;
}

function appendIfPresent(params, name, value) {
  const text = cleanText(value);
  if (text) params.set(name, text);
}

function dateOrdinal(year, month, day) {
  return Math.floor(Date.UTC(year, month - 1, day) / 86400000);
}

function parseYmd(value) {
  const match = cleanText(value).match(/^(\d{4})-(\d{2})-(\d{2})$/);
  if (!match) return null;
  const year = Number(match[1]);
  const month = Number(match[2]);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a limit of at most 50; omit the option to use the default 20.
  2. Clamp at the call site: Math.min(Math.max(1, n), 50) before invoking.
  3. If you need more than 50 events, paginate — call repeatedly (possibly with date filters via date/dateTo) and merge results.

Example fix

// before
await events({ limit: 200 }); // ArgumentError: must be <= 50
// after
const n = Math.min(Math.max(1, Number(userLimit) || 20), 50);
await events({ limit: n });
Defensive patterns

Strategy: validation

Validate before calling

const MAX_LIMIT = 50;
function clampLimit(value) {
  const n = typeof value === 'number' ? value : Number(String(value ?? '').trim());
  if (!Number.isInteger(n) || n <= 0) return 20;
  return Math.min(n, MAX_LIMIT);
}

Type guard

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

Try / catch

try {
  await events({ limit });
} catch (err) {
  if (err instanceof ArgumentError && /limit must be <= 50/.test(err.message)) {
    await events({ limit: 50 }); // clamp to maximum
  } else throw err;
}

Prevention

When it happens

Trigger: limit(100), limit('500'), limit(51) — any integer value greater than 50 on any call path routed through requireLimit (the events listing's limit option).

Common situations: Users expecting an unlimited/paginated fetch passing a large number; porting code from another API whose max page size is 100; generating limit from page-size math that exceeds the site's ceiling.

Related errors


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