{"record":{"id":"8ca91961f2184341","repo":"jackwener/OpenCLI","slug":"must-be-a-positive-integer","errorCode":null,"errorMessage":"must be a positive integer","messagePattern":"must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/yuanbao/history.js","lineNumber":29,"sourceCode":"\ncli({\n    site: 'yuanbao',\n    name: 'history',\n    access: 'read',\n    description: 'List recent Yuanbao conversations from the sidebar (requires login)',\n    domain: YUANBAO_DOMAIN,\n    strategy: Strategy.COOKIE,\n    browser: true,\n    siteSession: 'persistent',\n    navigateBefore: false,\n    args: [\n        { name: 'limit', type: 'int', default: 20, help: 'Max conversations to list (sidebar virtual scroll caps actual count)' },\n    ],\n    columns: ['Index', 'Title', 'AgentId', 'SessionId', 'Url'],\n    func: async (page, kwargs) => {\n        const limit = Number(kwargs.limit ?? 20);\n        if (!Number.isInteger(limit) || limit <= 0) {\n            throw new ArgumentError('limit', 'must be a positive integer');\n        }\n        await ensureYuanbaoPage(page);\n        if (await hasLoginGate(page)) {\n            throw authRequired('Yuanbao opened a login gate when reading the sidebar.');\n        }\n        await page.wait(1.5);\n        const sessions = await getYuanbaoSessionList(page, limit);\n        if (!sessions.length) {\n            throw new EmptyResultError(\n                'yuanbao history',\n                '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.',\n            );\n        }\n        return sessions.map((s, i) => ({\n            Index: i + 1,\n            Title: s.title || '(untitled)',\n            AgentId: s.agentId,\n            SessionId: s.cid,","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/yuanbao/history.js#L11-L47","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a whole number >= 1, e.g. `yuanbao history --limit 20`","If the value comes from a config/script, validate it with Number.isInteger(v) && v > 0 before invoking","Omit the flag entirely to use the built-in default of 20"],"exampleFix":"// before\nyuanbao history --limit 0\n// after\nyuanbao history --limit 20","handlingStrategy":"validation","validationCode":"function isValidLimit(v){const n=Number(v);return Number.isInteger(n)&&n>0;}\nif(!isValidLimit(userLimit)) throw new Error('limit must be a positive integer');","typeGuard":"const isPositiveInt = (v) => typeof v === 'number' && Number.isInteger(v) && v > 0;","tryCatchPattern":"try {\n  await cli.yuanbaoHistory({ limit: 20 });\n} catch (e) {\n  if (e.name === 'ArgumentError' && e.param === 'limit') {\n    console.error('Bad --limit; using default 20');\n  } else throw e;\n}","preventionTips":["Validate numeric CLI args at script boundaries before invoking","Never pass raw user/env strings as limit without Number() coercion","Remember 0 is invalid here — the default is 20, not 'unlimited'"],"tags":["validation","argument-error","cli"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}