jackwener/OpenCLI · warning · EmptyResultError

zhihu collections

zhihu collections

Error message

No favorite collections were returned for the logged-in user.

What it means

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.

Source

Thrown at clis/zhihu/collections.js:112

          if (Number.isInteger(parsedOffset) && parsedOffset > offset) {
            offset = parsedOffset;
            continue;
          }
        } catch {}
      }
      if (items.length < currentFetchLimit) break;
      const fallbackOffset = offset + items.length;
      if (fallbackOffset <= offset) break;
      offset = fallbackOffset;
      if (totals && offset >= totals) break;
    }

    if (totals > 0) {
      log.info(`共有 ${totals} 个收藏夹`);
    }

    if (collected.length === 0) {
      throw new EmptyResultError('zhihu collections', 'No favorite collections were returned for the logged-in user.');
    }

    return collected.slice(0, requestedLimit).map((item, i) => ({
      rank: i + 1,
      title: item.title || '未命名',
      item_count: item.item_count ?? item.answer_count ?? 0,
      description: item.description || '',
      collection_id: String(item.id || ''),
    }));
  },
});

export const __test__ = {
  validatePositiveInt,
  collectionKey,
};

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open Chrome/Chromium in the connected browser session and log in to https://www.zhihu.com, then re-run the command.
  2. Verify the account actually has favorite collections by visiting zhihu.com/collections in the browser.
  3. Re-run the command once to rule out a transient empty page or rate-limit interstitial.
  4. If login is confirmed and collections exist but the error persists, update/patch the collections scrape selectors for the current Zhihu DOM.

Example fix

// before: script assumes collections always exist
const cols = await zhihuCollections();
console.log(cols[0].title);
// after: guard against the EMPTY_RESULT (exit 66) case
try {
  const cols = await zhihuCollections();
  console.log(cols[0].title);
} catch (e) {
  if (e.code === 'EMPTY_RESULT') console.log('No collections (logged in?)');
  else throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// cannot check collections without the call; at minimum verify login first
const me = await zhihuMe(); // throws AuthRequiredError if not logged in

Type guard

function hasCollections(v) { return Array.isArray(v) && v.length > 0; }

Try / catch

try {
  const cols = await zhihuCollections();
} catch (e) {
  if (e.code === 'EMPTY_RESULT') {
    console.warn('zhihu collections empty — check login at zhihu.com');
    return [];
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/143a6551ffaa5a2a. Report an issue: GitHub.