jackwener/OpenCLI · info · EmptyResultError
zhihu search
Error message
zhihu search
What it means
This is an EmptyResultError thrown when a completed zhihu search produced zero rows for the given query and type filter. It is the library's way of distinguishing 'the command ran fine but found nothing' from command failures, using the type and query in the message (e.g. 'No answer results found for "x"').
Source
Thrown at clis/zhihu/search.js:184
if (type !== 'all' && normalized.row.type !== type) continue;
if (seen.has(normalized.key)) continue;
seen.add(normalized.key);
results.push(normalized.row);
if (results.length >= resultLimit) break;
}
if (results.length >= resultLimit) break;
if (data.paging?.is_end) break;
const next = normalizeSearchUrl(data.paging?.next);
if (!next) {
throw new CommandExecutionError('Zhihu search pagination returned malformed next URL');
}
if (visited.has(next)) {
throw new CommandExecutionError('Zhihu search pagination returned a repeated next URL');
}
url = next;
}
if (results.length === 0) {
throw new EmptyResultError('zhihu search', `No ${type === 'all' ? '' : `${type} `}results found for "${query}"`);
}
return results.map((row, i) => {
return {
rank: i + 1,
...row,
};
});
},
});
export const __test__ = {
stripHtml,
itemKey,
itemUrl,
normalizeSearchUrl,
parseLimit,
requireQuery,
requireType,View on GitHub (pinned to 49907e53dc)
Solutions
- Retry with a broader or corrected query string
- Drop or change the --type filter (use 'all')
- Check the query on zhihu.com in a browser to confirm results exist
- If content is login-gated, ensure the browser session used by the CLI is authenticated
Defensive patterns
Strategy: try-catch
Validate before calling
// Can't fully predict; sanity-check the query is non-empty before calling
if (!query.trim()) throw new Error('query required before zhihu search'); Try / catch
try {
const results = await zhihuSearch(query, { type });
} catch (err) {
if (err instanceof EmptyResultError || /No .* results found/.test(err.message)) {
console.log(`No results for "${query}" (${type}); try a broader query or type 'all'.`);
return [];
}
throw err;
} Prevention
- Catch EmptyResultError separately from other errors and treat it as an empty set
- Verify the query has matches on zhihu.com before assuming a bug
- Default to type 'all' when unsure of content type
- Check authentication state if Zhihu gates results behind login
When it happens
Trigger: Any searchZhihu invocation where the API returns pages successfully but data.data contains no items matching the query/type, so results.length === 0 after pagination ends.
Common situations: Misspelled or overly specific query, wrong --type filter (e.g. article when only answers exist), query matching deleted/private content, region or login state causing Zhihu to return empty results.
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 12306 stations match "${keyword}"
- ${label}
- No papers found for author "${authorText}". Try alternate sp
- No papers found. Try a different keyword.
- crates search
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/901617f0b8849901.
Report an issue: GitHub.