jackwener/OpenCLI · error · ArgumentError

limit must be a positive integer

Error message

limit must be a positive integer

What it means

normalizeLimit in clis/uisdc/news.js validates the user-supplied --limit option and throws ArgumentError 'limit must be a positive integer' when the value is not an integer greater than 0. This guards the API pagination call: a non-numeric, fractional, zero, or negative limit would produce a meaningless or invalid request. The error message includes an example invocation with DEFAULT_LIMIT.

Source

Thrown at clis/uisdc/news.js:12

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

const UISDC_NEWS_URL = 'https://www.uisdc.com/news';
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 uisdc news --limit ${DEFAULT_LIMIT}`);
    }
    if (limit > MAX_LIMIT) {
        throw new ArgumentError(`limit must be <= ${MAX_LIMIT}`, `Example: opencli uisdc news --limit ${MAX_LIMIT}`);
    }
    return limit;
}

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

function buildExtractUisdcNewsJs() {
    return `
      (() => {
        const cards = Array.from(document.querySelectorAll(
          '.news-list > .news-item:first-child > .item-content > .dubao-items > .dubao-item'
        ));
        if (cards.length === 0) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a positive whole number, e.g. `opencli uisdc news --limit 10`
  2. Use the suggested default from the error message: `opencli uisdc news --limit ${DEFAULT_LIMIT}` (see clis/uisdc/news.js)
  3. Check shell scripts/config for empty or malformed variables feeding --limit (`echo "${LIMIT_VAR}"` to inspect)
  4. Remember the ceiling: keep the value between 1 and 50 (MAX_LIMIT)

Example fix

// before
$ opencli uisdc news --limit 0
ArgumentError: limit must be a positive integer
// after
$ opencli uisdc news --limit 10
Defensive patterns

Strategy: validation

Validate before calling

function parseLimit(raw, { DEFAULT_LIMIT, MAX_LIMIT } = { DEFAULT_LIMIT: 10, MAX_LIMIT: 50 }) {
  const limit = Number(raw ?? DEFAULT_LIMIT);
  if (!Number.isInteger(limit) || limit <= 0) throw new Error('limit must be a positive integer');
  if (limit > MAX_LIMIT) throw new Error(`limit must be <= ${MAX_LIMIT}`);
  return limit;
}

Type guard

function isValidLimit(v) {
  return Number.isInteger(Number(v)) && Number(v) > 0;
}

Try / catch

try {
  await opencli('uisdc', 'news', ['--limit', limitArg]);
} catch (err) {
  if (/limit must be/.test(err.message)) {
    console.error('Use a whole number between 1 and 50, e.g. --limit 10');
  } else { throw err; }
}

Prevention

When it happens

Trigger: Running `opencli uisdc news --limit abc` (non-numeric), `--limit 0`, `--limit -3`, or `--limit 2.5`; also passing an empty/whitespace value that coerces to NaN. Note limits above 50 throw a different message ('limit must be <= 50').

Common situations: Typo in the flag value (`--limt 1o` style fat-fingering); scripting the CLI with a shell variable that is empty or unset; assuming the limit accepts 0 as 'all items'; copying a float from a config file.

Related errors


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