{"record":{"id":"c5d16af839d47a0e","repo":"jackwener/OpenCLI","slug":"limit","errorCode":null,"errorMessage":"limit","messagePattern":"limit","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/yuanbao/shared.js","lineNumber":214,"sourceCode":"        .filter((item) => item.id && (item.text || item.html));\n}\n\n/**\n * Enumerate sidebar conversation entries.\n *\n * Each `.yb-recent-conv-list__item` exposes:\n *   - `dt-cid`     — conversation UUID\n *   - `dt-agent-id`— agent slug\n *   - `[data-item-name]` — display title\n *\n * We do NOT trigger sidebar virtual scroll here — Yuanbao loads the visible\n * window only, so callers requesting a higher `limit` than the rendered count\n * get whatever is currently rendered. That matches Yuanbao's own UX.\n */\nexport async function getYuanbaoSessionList(page, limit) {\n    const cap = Number(limit ?? 20);\n    if (!Number.isInteger(cap) || cap <= 0) {\n        throw new ArgumentError('limit', 'must be a positive integer');\n    }\n    const result = await page.evaluate(`(() => {\n    ${IS_VISIBLE_JS}\n    const nodes = Array.from(document.querySelectorAll('.yb-recent-conv-list__item'))\n      .filter((node) => isVisible(node));\n    return nodes.map((node) => {\n      const cid = node.getAttribute('dt-cid') || '';\n      const agentId = node.getAttribute('dt-agent-id') || '';\n      const titleEl = node.querySelector('[data-item-name]');\n      const title = (titleEl?.getAttribute('data-item-name') || titleEl?.textContent || '').trim();\n      return { cid, agentId, title };\n    });\n  })()`);\n    if (!Array.isArray(result)) return [];\n    return result\n        .map((item) => ({\n            cid: String(item?.cid || '').toLowerCase(),\n            agentId: String(item?.agentId || ''),","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/yuanbao/shared.js#L196-L232","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a positive integer, e.g. getYuanbaoSessionList(page, 20)","Coerce and validate before calling: const n = Number(v); if (Number.isInteger(n) && n > 0) ...","Omit the argument to use the built-in default cap of 20"],"exampleFix":"// before\nawait getYuanbaoSessionList(page, req.query.limit);\n// after\nconst n = Number(req.query.limit ?? 20);\nif (!Number.isInteger(n) || n <= 0) throw new Error('limit must be a positive integer');\nawait getYuanbaoSessionList(page, n);","handlingStrategy":"validation","validationCode":"const n = Number(limit ?? 20);\nif (!Number.isInteger(n) || n <= 0) throw new Error('limit must be a positive integer');\nawait getYuanbaoSessionList(page, n);","typeGuard":"const isPositiveInt = (v) => typeof v === 'number' && Number.isInteger(v) && v > 0;","tryCatchPattern":"try {\n  const sessions = await getYuanbaoSessionList(page, limit);\n} catch (e) {\n  if (e.name === 'ArgumentError' && e.param === 'limit') {\n    return getYuanbaoSessionList(page, 20);\n  }\n  throw e;\n}","preventionTips":["Coerce with Number() and validate before every direct library call","Guard against NaN from Number(undefined) when limit is optional","Wrap this function in a small helper with a validated default of 20"],"tags":["validation","argument-error","library-api"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}