{"record":{"id":"8e02bf26652e52f4","repo":"jackwener/OpenCLI","slug":"zhihu-collections-name-must-be-a-positive-int","errorCode":null,"errorMessage":"zhihu collections --${name} must be a positive integer","messagePattern":"zhihu collections --(.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/collections.js","lineNumber":8,"sourceCode":"import { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { log } from '@jackwener/opencli/logger';\n\nfunction validatePositiveInt(value, name) {\n  const n = Number(value);\n  if (!Number.isInteger(n) || n <= 0) {\n    throw new ArgumentError(`zhihu collections --${name} must be a positive integer`, 'Example: opencli zhihu collections --limit 20');\n  }\n  return n;\n}\n\nasync function fetchJson(page, url, errorLabel) {\n  const data = await page.evaluate(`\n    (async () => {\n      const r = await fetch(${JSON.stringify(url)}, { credentials: 'include' });\n      if (!r.ok) return { __httpError: r.status };\n      return await r.json();\n    })()\n  `);\n\n  if (!data || data.__httpError) {\n    const status = data?.__httpError;\n    if (status === 401 || status === 403) {\n      throw new AuthRequiredError('www.zhihu.com', `${errorLabel} from Zhihu failed. Please ensure you are logged in.`);\n    }","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/collections.js#L1-L26","documentation":"validatePositiveInt in collections.js throws ArgumentError when a numeric option (limit/offset, referenced by name) is not an integer greater than 0. It is used to validate pagination arguments before requests are made, e.g. requestedLimit for the collections listing.","triggerScenarios":"Passing --limit 0, --limit -5, a non-integer like --limit 2.5, or a non-numeric value like --limit abc / empty string.","commonSituations":"Copy-pasting values with units ('20 items'); shell quoting dropping the value so Number(undefined) is NaN; confusing offset semantics and passing 0 where a positive value is required.","solutions":["Pass a positive integer, e.g. opencli zhihu collections --limit 20","Check the shell actually forwarded the value (quote it if it contains special chars)","Use whole numbers without units or decimals","For offsets that may be zero, use the command that validates non-negative ints instead"],"exampleFix":"// before\nopencli zhihu collections --limit 0\n// after\nopencli zhihu collections --limit 20","handlingStrategy":"validation","validationCode":"function assertPositiveInt(value, name) {\n  const n = Number(value);\n  if (!Number.isInteger(n) || n <= 0) throw new Error(`--${name} must be a positive integer, got: ${JSON.stringify(value)}`);\n  return n;\n}\nassertPositiveInt(process.argv.limit, 'limit');","typeGuard":"function isPositiveInt(v) { return Number.isInteger(v) && v > 0; }","tryCatchPattern":"try {\n  return await zhihuCollections({ limit: rawLimit });\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.includes('must be a positive integer')) {\n    return zhihuCollections({ limit: 20 });\n  }\n  throw e;\n}","preventionTips":["Always pass whole positive numbers without units","Quote option values in shell to avoid them being dropped","Default to limit 20 when unsure","Validate CLI args with a shared helper before invoking commands"],"tags":["validation","argument","cli","pagination"],"backgroundTag":"invalid-argument-input","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}