jackwener/OpenCLI · error · ArgumentError

limit

Error message

limit

What it means

getYuanbaoSessionList validates its limit before scraping the sidebar: the value must be a Number.isInteger and > 0. It throws ArgumentError named 'limit'. This mirrors the CLI-level check in history.js but guards direct callers of the exported function too.

Source

Thrown at clis/yuanbao/shared.js:214

        .filter((item) => item.id && (item.text || item.html));
}

/**
 * Enumerate sidebar conversation entries.
 *
 * Each `.yb-recent-conv-list__item` exposes:
 *   - `dt-cid`     — conversation UUID
 *   - `dt-agent-id`— agent slug
 *   - `[data-item-name]` — display title
 *
 * We do NOT trigger sidebar virtual scroll here — Yuanbao loads the visible
 * window only, so callers requesting a higher `limit` than the rendered count
 * get whatever is currently rendered. That matches Yuanbao's own UX.
 */
export async function getYuanbaoSessionList(page, limit) {
    const cap = Number(limit ?? 20);
    if (!Number.isInteger(cap) || cap <= 0) {
        throw new ArgumentError('limit', 'must be a positive integer');
    }
    const result = await page.evaluate(`(() => {
    ${IS_VISIBLE_JS}
    const nodes = Array.from(document.querySelectorAll('.yb-recent-conv-list__item'))
      .filter((node) => isVisible(node));
    return nodes.map((node) => {
      const cid = node.getAttribute('dt-cid') || '';
      const agentId = node.getAttribute('dt-agent-id') || '';
      const titleEl = node.querySelector('[data-item-name]');
      const title = (titleEl?.getAttribute('data-item-name') || titleEl?.textContent || '').trim();
      return { cid, agentId, title };
    });
  })()`);
    if (!Array.isArray(result)) return [];
    return result
        .map((item) => ({
            cid: String(item?.cid || '').toLowerCase(),
            agentId: String(item?.agentId || ''),

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a positive integer, e.g. getYuanbaoSessionList(page, 20)
  2. Coerce and validate before calling: const n = Number(v); if (Number.isInteger(n) && n > 0) ...
  3. Omit the argument to use the built-in default cap of 20

Example fix

// before
await getYuanbaoSessionList(page, req.query.limit);
// after
const n = Number(req.query.limit ?? 20);
if (!Number.isInteger(n) || n <= 0) throw new Error('limit must be a positive integer');
await getYuanbaoSessionList(page, n);
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(limit ?? 20);
if (!Number.isInteger(n) || n <= 0) throw new Error('limit must be a positive integer');
await getYuanbaoSessionList(page, n);

Type guard

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

Try / catch

try {
  const sessions = await getYuanbaoSessionList(page, limit);
} catch (e) {
  if (e.name === 'ArgumentError' && e.param === 'limit') {
    return getYuanbaoSessionList(page, 20);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling getYuanbaoSessionList(page, 0), a negative number, NaN (e.g. undefined coerced via Number('abc')), a float, or a non-numeric type from a programmatic caller that skips the CLI's own validation.

Common situations: Library consumers wiring their own commands around getYuanbaoSessionList with config-derived limits; NaN leaks from Number(undefined); JSON config where limit is a string like '20' that was never converted in a custom caller path.

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