{"record":{"id":"143a6551ffaa5a2a","repo":"jackwener/OpenCLI","slug":"zhihu-collections","errorCode":"zhihu collections","errorMessage":"No favorite collections were returned for the logged-in user.","messagePattern":"No favorite collections were returned for the logged-in user\\.","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/zhihu/collections.js","lineNumber":112,"sourceCode":"          if (Number.isInteger(parsedOffset) && parsedOffset > offset) {\n            offset = parsedOffset;\n            continue;\n          }\n        } catch {}\n      }\n      if (items.length < currentFetchLimit) break;\n      const fallbackOffset = offset + items.length;\n      if (fallbackOffset <= offset) break;\n      offset = fallbackOffset;\n      if (totals && offset >= totals) break;\n    }\n\n    if (totals > 0) {\n      log.info(`共有 ${totals} 个收藏夹`);\n    }\n\n    if (collected.length === 0) {\n      throw new EmptyResultError('zhihu collections', 'No favorite collections were returned for the logged-in user.');\n    }\n\n    return collected.slice(0, requestedLimit).map((item, i) => ({\n      rank: i + 1,\n      title: item.title || '未命名',\n      item_count: item.item_count ?? item.answer_count ?? 0,\n      description: item.description || '',\n      collection_id: String(item.id || ''),\n    }));\n  },\n});\n\nexport const __test__ = {\n  validatePositiveInt,\n  collectionKey,\n};\n","sourceCodeStart":94,"sourceCodeEnd":129,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/collections.js#L94-L129","documentation":"The `zhihu collections` command threw EmptyResultError (code EMPTY_RESULT, exit code 66 / EX_NOINPUT) because scraping the logged-in user's favorite collections (收藏夹) produced an empty array. The library throws this whenever the collected list is length 0 after parsing the collections page, distinguishing 'no data' from a hard failure. It usually means the session is not actually logged in, the page structure changed, or the account genuinely has no collections.","triggerScenarios":"Running `opencli zhihu collections` when the browser session cookies are missing/expired so the page shows a login wall (0 items parsed); Zhihu DOM changes make the collections parser extract nothing; or the account truly has zero favorite collections while --limit requests > 0.","commonSituations":"Developers running the CLI headlessly without first logging into zhihu.com in the connected Chrome profile; a Zhihu front-end update renaming the collections list selectors; testing with a fresh account that has no favorites; rate limiting serving an empty/interstitial page.","solutions":["Open Chrome/Chromium in the connected browser session and log in to https://www.zhihu.com, then re-run the command.","Verify the account actually has favorite collections by visiting zhihu.com/collections in the browser.","Re-run the command once to rule out a transient empty page or rate-limit interstitial.","If login is confirmed and collections exist but the error persists, update/patch the collections scrape selectors for the current Zhihu DOM."],"exampleFix":"// before: script assumes collections always exist\nconst cols = await zhihuCollections();\nconsole.log(cols[0].title);\n// after: guard against the EMPTY_RESULT (exit 66) case\ntry {\n  const cols = await zhihuCollections();\n  console.log(cols[0].title);\n} catch (e) {\n  if (e.code === 'EMPTY_RESULT') console.log('No collections (logged in?)');\n  else throw e;\n}","handlingStrategy":"try-catch","validationCode":"// cannot check collections without the call; at minimum verify login first\nconst me = await zhihuMe(); // throws AuthRequiredError if not logged in","typeGuard":"function hasCollections(v) { return Array.isArray(v) && v.length > 0; }","tryCatchPattern":"try {\n  const cols = await zhihuCollections();\n} catch (e) {\n  if (e.code === 'EMPTY_RESULT') {\n    console.warn('zhihu collections empty — check login at zhihu.com');\n    return [];\n  }\n  throw e;\n}","preventionTips":["Always log in to zhihu.com in the connected browser profile before running read commands.","Treat exit code 66 (EMPTY_RESULT) as 'no data', not a crash, in scripts.","Spot-check the account's collections page in a browser when the CLI returns empty."],"tags":["zhihu","empty-result","scraping","authentication"],"backgroundTag":"empty-scrape-result","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}