jackwener/OpenCLI · error · ArgumentError

must be a positive integer

Error message

must be a positive integer

What it means

The yuanbao history command accepts a --limit argument controlling how many sidebar conversations to list. Before touching the browser, the handler coerces the value with Number() and rejects anything that is not an integer greater than zero. This fails fast so the downstream DOM scraper (getYuanbaoSessionList) never receives a nonsensical count.

Source

Thrown at clis/yuanbao/history.js:29

cli({
    site: 'yuanbao',
    name: 'history',
    access: 'read',
    description: 'List recent Yuanbao conversations from the sidebar (requires login)',
    domain: YUANBAO_DOMAIN,
    strategy: Strategy.COOKIE,
    browser: true,
    siteSession: 'persistent',
    navigateBefore: false,
    args: [
        { name: 'limit', type: 'int', default: 20, help: 'Max conversations to list (sidebar virtual scroll caps actual count)' },
    ],
    columns: ['Index', 'Title', 'AgentId', 'SessionId', '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');
        }
        await ensureYuanbaoPage(page);
        if (await hasLoginGate(page)) {
            throw authRequired('Yuanbao opened a login gate when reading the sidebar.');
        }
        await page.wait(1.5);
        const sessions = await getYuanbaoSessionList(page, limit);
        if (!sessions.length) {
            throw new EmptyResultError(
                'yuanbao history',
                'No Yuanbao conversations found in the sidebar. Either the account is logged out, the sidebar is collapsed, or the user truly has no chat history yet.',
            );
        }
        return sessions.map((s, i) => ({
            Index: i + 1,
            Title: s.title || '(untitled)',
            AgentId: s.agentId,
            SessionId: s.cid,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a whole number >= 1, e.g. `yuanbao history --limit 20`
  2. If the value comes from a config/script, validate it with Number.isInteger(v) && v > 0 before invoking
  3. Omit the flag entirely to use the built-in default of 20

Example fix

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

Strategy: validation

Validate before calling

function isValidLimit(v){const n=Number(v);return Number.isInteger(n)&&n>0;}
if(!isValidLimit(userLimit)) throw new Error('limit must be a positive integer');

Type guard

const isPositiveInt = (v) => typeof v === 'number' && Number.isInteger(v) && v > 0;

Try / catch

try {
  await cli.yuanbaoHistory({ limit: 20 });
} catch (e) {
  if (e.name === 'ArgumentError' && e.param === 'limit') {
    console.error('Bad --limit; using default 20');
  } else throw e;
}

Prevention

When it happens

Trigger: Running `yuanbao history --limit 0`, a negative value like --limit -5, a non-numeric string such as --limit abc, or a float like --limit 2.5. Also an empty string limit that coerces to NaN.

Common situations: Shell scripts parameterizing the limit with an unset or malformed variable; copy-pasted examples with float defaults; passing 0 intending 'unlimited' when the flag actually requires a positive count.

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