jackwener/OpenCLI · warning · EmptyResultError

No WeRead books found for "${bookQuery}"

Error message

No WeRead books found for "${bookQuery}"

What it means

searchBookByQuery throws EmptyResultError 'No WeRead books found for "<query>"' when the search API responds correctly but the books array is empty. This is a valid, expected outcome signaling that the query matched nothing — not a malfunction of the library.

Source

Thrown at clis/weread/book-search.js:225

    if (author) {
        const exact = htmlEntries.filter((entry) => normalizeSearchText(entry.title) === title && normalizeSearchText(entry.author) === author);
        if (exact.length === 1)
            return exact[0].readerUrl;
    }
    const sameTitle = htmlEntries.filter((entry) => normalizeSearchText(entry.title) === title);
    return sameTitle.length === 1 ? sameTitle[0].readerUrl : '';
}

async function searchBookByQuery(bookQuery, bookRank) {
    const url = new URL('/web/search/global', `${WEREAD_WEB_ORIGIN}/web`);
    url.searchParams.set('keyword', bookQuery);
    const data = await fetchJson(url, 'WeRead book search');
    if (!Array.isArray(data?.books)) {
        throw new CommandExecutionError('WeRead book search returned malformed books');
    }
    const books = data.books;
    if (books.length === 0) {
        throw new EmptyResultError('weread book-search', `No WeRead books found for "${bookQuery}"`);
    }
    if (bookRank > books.length) {
        throw new ArgumentError(`book-rank must be <= ${books.length}`, `Only ${books.length} book search result(s) were returned for "${bookQuery}"`);
    }
    const bookInfo = books[bookRank - 1]?.bookInfo ?? {};
    const selected = {
        bookId: normalizeSearchText(bookInfo.bookId),
        title: normalizeSearchText(bookInfo.title),
        author: normalizeSearchText(bookInfo.author),
        readerUrl: '',
        chapters: [],
    };
    if (!selected.bookId) {
        throw new CommandExecutionError(`WeRead book search result ${bookRank} is missing bookId`);
    }
    const htmlEntries = await loadSearchHtmlEntries(bookQuery);
    selected.readerUrl = resolveReaderUrlForBook(selected, htmlEntries);
    const readerMetadata = await loadReaderMetadata(selected.readerUrl);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Shorten the query to distinctive keywords (title + author)
  2. Remove quotes/punctuation and extra words from the search string
  3. Try alternate spellings or the original-language title
  4. Verify the book actually exists on weread.qq.com via web search first
  5. Handle EmptyResultError in scripts as a 'no match' branch, not a crash

Example fix

// before
weread book-search --query "The Three-Body Problem by Cixin Liu, translated by Ken Liu, first edition"
// after
weread book-search --query "三体 刘慈欣"
Defensive patterns

Strategy: try-catch

Validate before calling

// Preflight your query: reject empty/overly long free-text before calling the CLI
const q = rawQuery.trim().replace(/["'\u201c\u201d]/g, '');
if (q.length < 2) throw new Error('Search query too short or empty');

Type guard

const isUsableQuery = (v) => typeof v === 'string' && v.trim().length >= 2;

Try / catch

try {
  await runCommand(['book-search', '--query', q]);
} catch (e) {
  if (e instanceof EmptyResultError || e.message.includes('No WeRead books found')) {
    console.log(`No results for "${q}" — try shorter keywords or the original title.`);
    process.exitCode = 0; // treat as empty, not failure
  } else throw e;
}

Prevention

When it happens

Trigger: A book title/author/ISBN with zero matches in WeRead's catalog, heavy typos or overly specific multi-word queries, non-Chinese titles absent from WeRead, or region-restricted content invisible to the caller.

Common situations: Users paste full sentences as the query, search for obscure foreign books, include publisher/edition text that breaks matching, or query in a language WeRead does not index.

Related errors


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