{"record":{"id":"4d604d173fefc2a6","repo":"jackwener/OpenCLI","slug":"limit-must-be-a-positive-integer-got-parsed-4d604d","errorCode":null,"errorMessage":"--limit must be a positive integer, got ${parsed}","messagePattern":"--limit must be a positive integer, got (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"warning","filePath":"clis/xiaohongshu/feed.js","lineNumber":25,"sourceCode":" * could not be passed to `note`/`comments`/`download` (which require a signed\n * URL). The hydrated store, by contrast, holds `entry.xsecToken` for every\n * first-screen note, so a func-mode read yields signed, drill-down-ready URLs.\n *\n * Mirrors rednote/feed.js: the hydrated store is camelCase on both sites\n * (`noteCard.displayTitle`, `interactInfo.likedCount`). This is the SSR store\n * shape, not the snake_case `/homefeed` API response the old tap intercepted.\n */\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { unwrapEvaluateResult } from './shared.js';\n\nfunction parseLimit(raw) {\n    const parsed = Number(raw ?? 20);\n    if (!Number.isFinite(parsed) || !Number.isInteger(parsed)) {\n        throw new ArgumentError(`--limit must be a positive integer, got ${JSON.stringify(raw)}`);\n    }\n    if (parsed < 1) {\n        throw new ArgumentError(`--limit must be a positive integer, got ${parsed}`);\n    }\n    return parsed;\n}\n\nconst FEEDS_READ_JS = `\n  (() => {\n    let pinia = null;\n    const probe = (el) => el?.__vue_app__?.config?.globalProperties?.$pinia ?? null;\n    pinia = probe(document.querySelector('#app'));\n    if (!pinia) {\n      // Some builds mount under a different root id; fall back to a full scan\n      // only when the standard mount node misses.\n      for (const el of document.querySelectorAll('*')) {\n        pinia = probe(el);\n        if (pinia) break;\n      }\n    }\n    if (!pinia || !pinia._s) return { error: 'no_pinia' };","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/feed.js#L7-L43","documentation":"parseLimit also rejects integers below 1. If the coerced value is a valid integer but parsed < 1 (e.g. 0 or -5), it throws ArgumentError with the numeric value. Note the error text says 'positive integer' but 0/negatives also fail here.","triggerScenarios":"Calling the feed command with --limit 0, --limit -1, or any negative integer.","commonSituations":"Users trying 'unlimited' with --limit 0, scripts computing a page size that underflows to 0 or negative, off-by-one bugs in wrapper scripts.","solutions":["Pass an integer >= 1: --limit 1 for a single item","Fix the upstream calculation producing 0/negative page sizes","Omit --limit to use the default of 20"],"exampleFix":"// before\nxhs feed --limit 0\n// after\nxhs feed --limit 20","handlingStrategy":"validation","validationCode":"const n = Number(raw);\nif (raw != null && Number.isInteger(n) && n < 1) throw new Error(`--limit must be >= 1, got ${n}`);","typeGuard":"function isPositiveLimit(raw) { if (raw == null) return true; const n = Number(raw); return Number.isInteger(n) && n >= 1; }","tryCatchPattern":"try {\n  await cli.feed({ limit });\n} catch (err) {\n  if (err instanceof ArgumentError && err.message.startsWith('--limit')) {\n    console.error('limit must be >= 1; defaulting to 20');\n  } else throw err;\n}","preventionTips":["Never use 0 or negatives for limits; clamp computed page sizes with Math.max(1, n)","Omit --limit for default behavior","Validate page-size math in wrapper scripts"],"tags":["cli","argument-validation"],"backgroundTag":"invalid-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}