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

  1. Shorten the query to a distinctive keyword (author surname or 2–4 core title words) and retry.
  2. Search in the language of the catalog edition (Chinese titles for WeRead content).
  3. Strip punctuation/quotes from the query; try the ISBN or alternate title.
  4. Treat EmptyResultError as a control-flow signal in scripts: catch it and report 'no results' instead of a generic failure.
  5. 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

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


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