{"record":{"id":"45f85d8552a055b0","repo":"jackwener/OpenCLI","slug":"zhihu-collection-name-must-be-a-positive-inte","errorCode":null,"errorMessage":"zhihu collection --${name} must be a positive integer","messagePattern":"zhihu collection --(.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/collection.js","lineNumber":9,"sourceCode":"import { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { log } from '@jackwener/opencli/logger';\nimport { stripHtml } from './text.js';\n\nfunction validatePositiveInt(value, name) {\n  const n = Number(value);\n  if (!Number.isInteger(n) || n <= 0) {\n    throw new ArgumentError(`zhihu collection --${name} must be a positive integer`, 'Example: opencli zhihu collection 83283292 --limit 20');\n  }\n  return n;\n}\n\nfunction validateNonNegativeInt(value, name) {\n  const n = Number(value);\n  if (!Number.isInteger(n) || n < 0) {\n    throw new ArgumentError(`zhihu collection --${name} must be a non-negative integer`, 'Example: opencli zhihu collection 83283292 --offset 0');\n  }\n  return n;\n}\n\nasync function fetchCollectionPage(page, collectionId, offset, limit) {\n  const url = `https://www.zhihu.com/api/v4/collections/${collectionId}/items?offset=${offset}&limit=${limit}`;\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 };","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/collection.js#L1-L27","documentation":"The zhihu collection command validates numeric options with validatePositiveInt, which throws ArgumentError when a value passed as a positive-integer option (e.g. --limit) is not an integer or is <= 0. This is input validation before any API call — the collection is never fetched.","triggerScenarios":"Passing `--limit 0`, `--limit -5`, `--limit abc`, `--limit 2.5`, or an empty string to `opencli zhihu collection <id>`; requestedLimit() calls validatePositiveInt on the option value.","commonSituations":"Shell variable interpolating empty or malformed values (`--limit \"${COUNT}\"` where COUNT is unset); copy-paste with decimals or thousands separators like `--limit 1,000`; scripting mistakes passing a float from JSON config.","solutions":["Pass a positive integer, e.g. `--limit 20`.","Check shell variables for emptiness/typos before interpolation; use defaults like `${COUNT:-20}`.","Use the suggested example from the error: `opencli zhihu collection 83283292 --limit 20`.","Catch ArgumentError in wrappers and validate/normalize the option first (parseInt, check > 0)."],"exampleFix":"// before\nopencli zhihu collection 83283292 --limit 0\n// ArgumentError: --limit must be a positive integer\n// after\nopencli zhihu collection 83283292 --limit 20","handlingStrategy":"validation","validationCode":"function toPositiveInt(v) { const n = Number(v); if (!Number.isInteger(n) || n <= 0) throw new Error(`--limit must be a positive integer, got: ${JSON.stringify(v)}`); return n; }","typeGuard":"function isPositiveInt(v) { return Number.isInteger(Number(v)) && Number(v) > 0; }","tryCatchPattern":"try { await collection(args); } catch (e) { if (/must be a positive integer/.test(e.message)) { console.error('Usage: opencli zhihu collection <id> --limit 20'); } throw e; }","preventionTips":["Validate/normalize CLI options with parseInt before invoking","Use shell defaults for variables: ${COUNT:-20}","Avoid floats/locale-formatted numbers (1,000) in configs","Copy the usage example from the error message"],"tags":["validation","arguments","cli","zhihu"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}