{"record":{"id":"e79496d60ebc53fc","repo":"jackwener/OpenCLI","slug":"zhihu-collection","errorCode":"zhihu collection","errorMessage":"No items found for collection ${collectionId}. The collection may be empty, private, or the offset may be out of range.","messagePattern":"No items found for collection (.+?)\\. The collection may be empty, private, or the offset may be out of range\\.","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/zhihu/collection.js","lineNumber":186,"sourceCode":"      if (items.length < currentFetchLimit) break;\n      const fallbackOffset = nextOffset + items.length;\n      if (fallbackOffset <= nextOffset) break;\n      nextOffset = fallbackOffset;\n      if (totals && nextOffset >= totals) break;\n    }\n    \n    // 计算总页数\n    const totalPages = Math.ceil(totals / pageLimit);\n    const currentPage = Math.floor(pageOffset / pageLimit) + 1;\n    \n    // 输出统计信息\n    if (totals > 0) {\n      log.info(`收藏夹共有 ${totals} 条内容，共 ${totalPages} 页`);\n      log.info(`当前第 ${currentPage} 页，显示第 ${pageOffset + 1} - ${Math.min(pageOffset + collected.length, totals)} 条`);\n    }\n\n    if (collected.length === 0) {\n      throw new EmptyResultError('zhihu collection', `No items found for collection ${collectionId}. The collection may be empty, private, or the offset may be out of range.`);\n    }\n\n    return collected.slice(0, requestedLimit).map((item, i) => mapCollectionItem(item, pageOffset + i + 1));\n  },\n});\n\nexport const __test__ = {\n  stripHtml,\n  validatePositiveInt,\n  validateNonNegativeInt,\n  itemKey,\n  mapCollectionItem,\n};\n","sourceCodeStart":168,"sourceCodeEnd":200,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/collection.js#L168-L200","documentation":"The command throws EmptyResultError (code 'zhihu collection') when the fetched page contains zero items, meaning no rows can be returned for the requested collection at the given offset. It surfaces the likely causes: empty collection, private collection, or offset beyond the total count.","triggerScenarios":"Calling with an offset >= the collection's total item count; the collection genuinely has no items; the collection is private/inaccessible so the API returns an empty list; auth degraded so items are filtered out and mapping yields nothing.","commonSituations":"Paging past the end of a small collection (e.g. --offset 100 on a 30-item collection); scraping another user's private favorites; a fresh/empty collection; expired login silently yielding empty data.","solutions":["Retry with offset 0 to confirm the collection has any accessible items","Verify you are logged in — private collections need your own session","Check the collection's total count (the CLI logs 收藏夹共有 N 条内容) and use an offset below it","Confirm the collection ID points to a public, non-empty collection"],"exampleFix":"// before\nopencli zhihu collection 83283292 --offset 200  // collection only has 30 items\n// after\nopencli zhihu collection 83283292 --offset 0 --limit 20","handlingStrategy":"fallback","validationCode":"if (offset >= knownTotal && knownTotal > 0) {\n  console.warn(`offset ${offset} >= total ${knownTotal}; clamping to 0`);\n  offset = 0;\n}","typeGuard":"function isNonNegativeInt(v) { return Number.isInteger(Number(v)) && Number(v) >= 0; }","tryCatchPattern":"try {\n  return await zhihuCollection(id, { offset });\n} catch (e) {\n  if (e instanceof EmptyResultError && offset > 0) return zhihuCollection(id, { offset: 0 });\n  throw e;\n}","preventionTips":["Start with offset 0 and read the logged total before paging","Clamp offsets to below the collection's total count","Verify login state — private collections return empty lists when anonymous","Confirm the collection is non-empty and public before automating"],"tags":["empty-result","pagination","zhihu"],"backgroundTag":"empty-result-set","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}