jackwener/OpenCLI · warning · EmptyResultError
weread search: No books were returned for query ${args.query
Error message
weread search: No books were returned for query ${args.query}. What it means
An EmptyResultError thrown by the `weread search` command when both the public API and the scraped HTML page yield zero books for the query. This is a deliberate, expected signal that the search legitimately found nothing — not a malfunction. It carries the command name ('weread search') and the query so callers can distinguish it from real failures.
Source
Thrown at clis/weread/search.js:155
domain: 'weread.qq.com',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'query', positional: true, required: true, help: 'Search keyword' },
{ name: 'limit', type: 'int', default: 10, help: 'Max results' },
],
columns: ['rank', 'title', 'author', 'bookId', 'url'],
func: async (args) => {
const [data, htmlEntries] = await Promise.all([
fetchWebApi('/search/global', { keyword: args.query }),
loadSearchHtmlEntries(String(args.query ?? '')),
]);
const books = data?.books ?? [];
if (!Array.isArray(books)) {
throw new CommandExecutionError('WeRead search API returned an unreadable books payload');
}
if (books.length === 0) {
throw new EmptyResultError('weread search', `No books were returned for query ${args.query}.`);
}
const { exactQueues, titleOnlyQueues } = buildSearchUrlQueues(htmlEntries);
const apiIdentityCounts = countSearchIdentities(books.map((item) => ({
title: item.bookInfo?.title ?? '',
author: item.bookInfo?.author ?? '',
})));
const htmlIdentityCounts = countSearchIdentities(htmlEntries.filter((entry) => entry.author));
const apiTitleCounts = countSearchTitles(books.map((item) => ({ title: item.bookInfo?.title ?? '' })));
const htmlTitleCounts = countSearchTitles(htmlEntries);
return books.slice(0, Number(args.limit)).map((item, i) => {
const title = item.bookInfo?.title ?? '';
const author = item.bookInfo?.author ?? '';
return {
rank: i + 1,
title,
author,
bookId: item.bookInfo?.bookId ?? '',
url: resolveSearchResultUrl({View on GitHub (pinned to 49907e53dc)
Solutions
- Shorten the query to a distinctive keyword (author surname or 2–4 core title words) and retry.
- Search in the language of the catalog edition (Chinese titles for WeRead content).
- Strip punctuation/quotes from the query; try the ISBN or alternate title.
- Treat EmptyResultError as a control-flow signal in scripts: catch it and report 'no results' instead of a generic failure.
- Confirm in a browser at https://weread.qq.com/web/search that the book exists at all.
Example fix
// before weread search "The Three Body Problem Book I Hard cover edition" // after weread search "三体"
Defensive patterns
Strategy: try-catch
Validate before calling
// Check the query is non-trivial before invoking the command
const q = query.trim();
if (q.length < 2) throw new Error('Query too short — likely to return zero results'); Try / catch
import { EmptyResultError } from '@jackwener/opencli/errors';
try {
const rows = await runWereadSearch(query);
} catch (e) {
if (e instanceof EmptyResultError) {
console.log(`No WeRead books match "${query}" — try a shorter or Chinese-language keyword`);
return [];
}
throw e;
} Prevention
- Treat EmptyResultError as expected control flow, not a crash
- Sanitize queries: trim, strip punctuation, keep 2–6 distinctive keywords
- Prefer catalog-language (Chinese) titles when searching WeRead
- Verify a book exists on weread.qq.com in a browser before scripting around it
When it happens
Trigger: GET /web/search/books and /search/global both return empty results for `args.query` — e.g. a misspelled title, an overly specific keyword, a query of rare/obscure content not in WeRead's catalog, or queries with only whitespace after coercion via String(args.query ?? '').
Common situations: Typo or wrong-language query (searching English title when only the Chinese edition exists); quoting/punctuation in the query that over-constrains matching; testing the CLI with random strings; a book that was removed from the WeRead catalog.
Related errors
- No dblp venues matched "${query}".
- weread book-search: No matches for "${query}" in book ${book
- No 12306 stations match "${keyword}"
- ${label}
- No papers found for author "${authorText}". Try alternate sp
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/4bf3cd704e7c115c.
Report an issue: GitHub.