{"record":{"id":"2967af260f0fc10d","repo":"jackwener/OpenCLI","slug":"collection-id-must-be-numeric","errorCode":null,"errorMessage":"Collection ID must be numeric","messagePattern":"Collection ID must be numeric","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/collection.js","lineNumber":126,"sourceCode":"    access: 'read',\n  description: '知乎收藏夹内容列表（需要登录）',\n  domain: 'www.zhihu.com',\n  strategy: Strategy.COOKIE,\n  browser: true,\n  args: [\n    { name: 'id', positional: true, required: true, help: '收藏夹 ID (数字，可从收藏夹 URL 中获取)' },\n    { name: 'offset', type: 'int', default: 0, help: '起始偏移量（用于分页）' },\n    { name: 'limit', type: 'int', default: 20, help: '每页数量（最大 20）' },\n  ],\n  columns: ['rank', 'type', 'title', 'author', 'votes', 'excerpt', 'url'],\n  func: async (page, kwargs) => {\n    const { id, offset = 0, limit = 20 } = kwargs;\n\n    const collectionId = String(id);\n\n    // 验证收藏夹 ID 为数字\n    if (!/^\\d+$/.test(collectionId)) {\n      throw new ArgumentError('Collection ID must be numeric', 'Example: opencli zhihu collection 83283292');\n    }\n\n    const pageOffset = validateNonNegativeInt(offset, 'offset');\n    const requestedLimit = validatePositiveInt(limit, 'limit');\n    const pageLimit = Math.min(requestedLimit, 20); // 知乎 API 限制每页最大 20\n\n    // 先访问知乎主页建立 session\n    await page.goto('https://www.zhihu.com');\n\n    const collected = [];\n    const seen = new Set();\n    let totals = 0;\n    let nextOffset = pageOffset;\n    const maxPages = Math.ceil(requestedLimit / pageLimit) + 2;\n    for (let pageIndex = 0; pageIndex < maxPages && collected.length < requestedLimit; pageIndex += 1) {\n      const currentFetchLimit = Math.min(pageLimit, requestedLimit - collected.length);\n      const data = await fetchCollectionPage(page, collectionId, nextOffset, currentFetchLimit);\n      const items = Array.isArray(data.data) ? data.data : [];","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/collection.js#L108-L144","documentation":"The command's data handler throws ArgumentError when the id kwarg is not a purely numeric string, checked with /^\\d+$/. Zhihu collection IDs are numeric, so any non-numeric input is rejected before any request is made.","triggerScenarios":"Passing a collection URL instead of its ID (e.g. 'https://www.zhihu.com/collection/83283292'), a value with whitespace, letters, or an empty string as id.","commonSituations":"Pasting the whole collection URL from the browser address bar; copying an ID with trailing whitespace or invisible characters; mixing up question IDs and collection IDs.","solutions":["Pass only the numeric collection ID, e.g. opencli zhihu collection 83283292","If you have a URL, extract the digits after /collection/ before invoking","Trim the input to remove stray whitespace","Check you are not using a different entity's ID (question/article)"],"exampleFix":"// before\nopencli zhihu collection \"https://www.zhihu.com/collection/83283292\"\n// after\nopencli zhihu collection 83283292","handlingStrategy":"validation","validationCode":"function assertNumericCollectionId(id) {\n  const s = String(id ?? '').trim();\n  if (!/^\\d+$/.test(s)) throw new Error(`collection id must be numeric, got: ${s}`);\n  return s;\n}","typeGuard":"function isNumericId(v) { return typeof v === 'string' || typeof v === 'number' ? /^\\d+$/.test(String(v)) : false; }","tryCatchPattern":"try {\n  return await zhihuCollection(rawId);\n} catch (e) {\n  if (e instanceof ArgumentError) {\n    const m = /collection\\/(\\d+)/.exec(String(rawId));\n    if (m) return zhihuCollection(m[1]);\n  }\n  throw e;\n}","preventionTips":["Pass only the numeric ID, never the full collection URL","Trim whitespace from pasted IDs","Validate IDs with /^\\d+$/ before invoking the command","Don't confuse collection IDs with question or article IDs"],"tags":["validation","argument","zhihu","cli"],"backgroundTag":"invalid-argument-input","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}