jackwener/OpenCLI · warning · EmptyResultError
weread-official ${command}
Error message
weread-official ${command} What it means
emptyResult throws an EmptyResultError whose message is the stable command label 'weread-official ${command}'. Commands like runRecommend, runSimilar, listNotebooks and listBookNotes call it when the WeRead API succeeds but returns no usable data, so callers can catch an expected 'no results' condition rather than crashing on undefined data.
Source
Thrown at clis/weread-official/utils.js:292
if (max !== undefined && n > max) {
throw new ArgumentError(`weread-official: ${label} must be <= ${max}`);
}
return n;
}
export function requireChoice(value, choices, label, defaultValue) {
const text = String(value ?? defaultValue ?? '').trim();
if (!choices.includes(text)) {
throw new ArgumentError(`weread-official: ${label} must be one of: ${choices.join(', ')}`);
}
return text;
}
// ── Empty-result helper ────────────────────────────────────────────────────
/** Throw EmptyResultError with a stable command label. */
export function emptyResult(command, hint) {
throw new EmptyResultError(`weread-official ${command}`, hint);
}
View on GitHub (pinned to 49907e53dc)
Solutions
- Catch EmptyResultError and treat it as an empty success (print a friendly 'no results' message, output [] or {}).
- Verify with another WeRead client that the account actually has notebooks/notes/recommendations.
- Loosen filters or options (e.g. remove restrictive mode/count choices) that may be excluding all results.
- If data should exist, re-authenticate / refresh cookies — sometimes stale sessions return degraded empty payloads.
Example fix
// before
const notes = await runBookNotes(bookId);
render(notes.items); // crashes on empty
// after
try {
const notes = await runBookNotes(bookId);
render(notes.items);
} catch (e) {
if (e instanceof EmptyResultError) render([]);
else throw e;
} Defensive patterns
Strategy: try-catch
Try / catch
import { EmptyResultError } from './errors.js';
try {
const res = await runRecommend(opts);
render(res);
} catch (e) {
if (e instanceof EmptyResultError) {
console.log('No results for this account/filter — treating as empty.');
render([]);
} else throw e;
} Prevention
- Always wrap list/recommend commands in a catch for EmptyResultError — empty accounts are normal.
- Distinguish 'no data' from 'failure' in exit codes and output so pipelines don't break.
- Pre-check the account has data via another command when a non-empty result is mandatory.
When it happens
Trigger: Calling runRecommend/runSimilar with items the account has no recommendations for, or listNotebooks/listBookNotes when the account genuinely has zero notebooks/notes — the empty payload triggers this thrown sentinel.
Common situations: New WeRead accounts with no reading history or highlights; filtering criteria that exclude everything; accounts where cloud notes were deleted; testing against a fresh login.
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 prices returned for train_no=${trainNo} ${fromStation.nam
- No 12306 stations match "${keyword}"
- CoinGecko returned no category data.
- coingecko top
- coingecko returned no trending coins.
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/1d33f448d0581cbe.
Report an issue: GitHub.