jackwener/OpenCLI · warning · EmptyResultError
zhihu collection
zhihu collection
Error message
No items found for collection ${collectionId}. The collection may be empty, private, or the offset may be out of range. What it means
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.
Source
Thrown at clis/zhihu/collection.js:186
if (items.length < currentFetchLimit) break;
const fallbackOffset = nextOffset + items.length;
if (fallbackOffset <= nextOffset) break;
nextOffset = fallbackOffset;
if (totals && nextOffset >= totals) break;
}
// 计算总页数
const totalPages = Math.ceil(totals / pageLimit);
const currentPage = Math.floor(pageOffset / pageLimit) + 1;
// 输出统计信息
if (totals > 0) {
log.info(`收藏夹共有 ${totals} 条内容,共 ${totalPages} 页`);
log.info(`当前第 ${currentPage} 页,显示第 ${pageOffset + 1} - ${Math.min(pageOffset + collected.length, totals)} 条`);
}
if (collected.length === 0) {
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.`);
}
return collected.slice(0, requestedLimit).map((item, i) => mapCollectionItem(item, pageOffset + i + 1));
},
});
export const __test__ = {
stripHtml,
validatePositiveInt,
validateNonNegativeInt,
itemKey,
mapCollectionItem,
};
View on GitHub (pinned to 49907e53dc)
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
Example fix
// before opencli zhihu collection 83283292 --offset 200 // collection only has 30 items // after opencli zhihu collection 83283292 --offset 0 --limit 20
Defensive patterns
Strategy: fallback
Validate before calling
if (offset >= knownTotal && knownTotal > 0) {
console.warn(`offset ${offset} >= total ${knownTotal}; clamping to 0`);
offset = 0;
} Type guard
function isNonNegativeInt(v) { return Number.isInteger(Number(v)) && Number(v) >= 0; } Try / catch
try {
return await zhihuCollection(id, { offset });
} catch (e) {
if (e instanceof EmptyResultError && offset > 0) return zhihuCollection(id, { offset: 0 });
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
- NO_DATA
- No recruiter-side chat sessions were returned.
- Boss returned no messages for this chat.
- coingecko exchanges
- Photo ID ${requestedPhotoId} was not found under subject ${s
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/e79496d60ebc53fc.
Report an issue: GitHub.