{"record":{"id":"c43fa53d4f42db31","repo":"jackwener/OpenCLI","slug":"limit-must-be-a-positive-integer-c43fa5","errorCode":null,"errorMessage":"limit must be a positive integer","messagePattern":"limit must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/qwen/history.js","lineNumber":36,"sourceCode":"\ncli({\n    site: 'qwen',\n    name: 'history',\n    access: 'read',\n    description: 'List recent Qianwen conversations (requires login)',\n    domain: QIANWEN_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 show (default 20, max 100)' },\n    ],\n    columns: ['Index', 'Title', 'Updated', '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        if (limit > 100) {\n            throw new ArgumentError('limit must be <= 100');\n        }\n        await ensureOnQianwen(page);\n        await dismissLoginModal(page);\n        await page.wait(1);\n        const result = await getSessionListFromApi(page, limit);\n        if (!result.ok) {\n            if (result.status === 401 || result.status === 403) throw authRequired();\n            if (!result.sessions.length) {\n                throw new CommandExecutionError(`Qianwen history API failed (status=${result.status}) ${result.error || ''}`.trim());\n            }\n        }\n        if (!result.sessions.length) {\n            throw new EmptyResultError('qwen history', 'No Qianwen conversations found.');\n        }\n        return result.sessions.slice(0, limit).map((s, i) => ({","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/qwen/history.js#L18-L54","documentation":"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.","triggerScenarios":"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.","commonSituations":"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').","solutions":["Pass a positive integer, e.g. --limit 20 (the default).","Coerce/validate the value before calling: Number.isInteger(Number(v)) && Number(v) > 0.","If coming from config/env, strip whitespace/units and parse with parseInt(v, 10).","Omit the flag entirely to use the default of 20."],"exampleFix":"// before\nqwen history --limit 0\n// after\nqwen history --limit 20","handlingStrategy":"validation","validationCode":"const n = Number(rawLimit);\nif (!Number.isInteger(n) || n <= 0) throw new Error(`limit must be a positive integer, got: ${rawLimit}`);","typeGuard":"function isPositiveInt(v) {\n  return typeof v === 'number' && Number.isInteger(v) && v > 0;\n}","tryCatchPattern":"try {\n  const rows = await qwenHistory({ limit });\n} catch (e) {\n  if (/limit must be a positive integer/.test(e.message)) {\n    const rows = await qwenHistory({ limit: 20 }); // fall back to default\n  } else throw e;\n}","preventionTips":["Always pass limit as a bare integer in the shell (quote values, avoid empty variables).","Sanitize env/config-sourced values with parseInt(v, 10) and an isNaN check.","Reject 0/negative/float input at the edge of your script before invoking the CLI.","Default to omitting --limit (default 20) when unsure."],"tags":["validation","argument-error","cli","qwen"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}