jackwener/OpenCLI · error · ArgumentError

limit must be a positive integer

Error message

limit must be a positive integer

What it means

The `qwen history` command validates its `limit` kwarg before scraping: Number(kwargs.limit ?? 20) must be an integer > 0, otherwise ArgumentError('limit must be a positive integer') is thrown at clis/qwen/history.js:36. Note the arg is declared type 'int', so a non-integer or non-positive value typically means the value was passed as a string/invalid token or explicitly set to 0/negative.

Source

Thrown at clis/qwen/history.js:36

cli({
    site: 'qwen',
    name: 'history',
    access: 'read',
    description: 'List recent Qianwen conversations (requires login)',
    domain: QIANWEN_DOMAIN,
    strategy: Strategy.COOKIE,
    browser: true,
    siteSession: 'persistent',
    navigateBefore: false,
    args: [
        { name: 'limit', type: 'int', default: 20, help: 'Max conversations to show (default 20, max 100)' },
    ],
    columns: ['Index', 'Title', 'Updated', 'Url'],
    func: async (page, kwargs) => {
        const limit = Number(kwargs.limit ?? 20);
        if (!Number.isInteger(limit) || limit <= 0) {
            throw new ArgumentError('limit must be a positive integer');
        }
        if (limit > 100) {
            throw new ArgumentError('limit must be <= 100');
        }
        await ensureOnQianwen(page);
        await dismissLoginModal(page);
        await page.wait(1);
        const result = await getSessionListFromApi(page, limit);
        if (!result.ok) {
            if (result.status === 401 || result.status === 403) throw authRequired();
            if (!result.sessions.length) {
                throw new CommandExecutionError(`Qianwen history API failed (status=${result.status}) ${result.error || ''}`.trim());
            }
        }
        if (!result.sessions.length) {
            throw new EmptyResultError('qwen history', 'No Qianwen conversations found.');
        }
        return result.sessions.slice(0, limit).map((s, i) => ({

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a positive integer, e.g. --limit 20 (the default).
  2. Coerce/validate the value before calling: Number.isInteger(Number(v)) && Number(v) > 0.
  3. If coming from config/env, strip whitespace/units and parse with parseInt(v, 10).
  4. Omit the flag entirely to use the default of 20.

Example fix

// before
qwen history --limit 0
// after
qwen history --limit 20
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(rawLimit);
if (!Number.isInteger(n) || n <= 0) throw new Error(`limit must be a positive integer, got: ${rawLimit}`);

Type guard

function isPositiveInt(v) {
  return typeof v === 'number' && Number.isInteger(v) && v > 0;
}

Try / catch

try {
  const rows = await qwenHistory({ limit });
} catch (e) {
  if (/limit must be a positive integer/.test(e.message)) {
    const rows = await qwenHistory({ limit: 20 }); // fall back to default
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the history func (programmatically or via CLI) with limit=0, a negative number, a non-numeric string like 'abc' (Number() => NaN, which fails Number.isInteger), or a float like 2.5.

Common situations: Shell quoting passing `--limit 0`; scripting with an unset variable that expands to '0' or empty leading to NaN; passing a limit read from config as a string with units ('20 items').

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