jackwener/OpenCLI · warning · EmptyResultError
${label} returned no items.
Error message
${label} returned no items. What it means
ensureItems validates that a Stack Exchange response contains a non-empty items array and throws EmptyResultError otherwise. It is a deliberate empty-result signal, not a failure of the request itself.
Source
Thrown at clis/stackoverflow/utils.js:97
'Inspect the URL in a browser for the canonical error context.',
);
}
return data;
}
/** Convert SE epoch seconds to YYYY-MM-DD. */
export function epochToDate(value) {
if (value == null || value === '') return '';
const n = Number(value);
if (!Number.isFinite(n) || n <= 0) return '';
return new Date(n * 1000).toISOString().slice(0, 10);
}
/** Throw EmptyResultError when an /items array is empty. */
export function ensureItems(data, label) {
const items = Array.isArray(data?.items) ? data.items : [];
if (items.length === 0) {
throw new EmptyResultError(label, `${label} returned no items.`);
}
return items;
}
const HTML_ENTITY_MAP = {
'&': '&', '<': '<', '>': '>', '"': '"',
''': "'", ''': "'", ' ': ' ',
};
/**
* Decode the small set of HTML entities Stack Exchange emits in display
* names and titles (e.g. "Jon Skeet's mentor"). Decimal/hex numeric
* refs are also handled.
*/
export function decodeHtmlEntities(value) {
if (value == null) return '';
return String(value)
.replace(/&#x([0-9a-fA-F]+);/g, (_, h) => String.fromCodePoint(parseInt(h, 16)))View on GitHub (pinned to 49907e53dc)
Solutions
- Loosen the search term or remove filters and retry
- Confirm the target entity exists on the site queried (correct site, correct id)
- Handle EmptyResultError in the caller as an expected empty state
- Check that the site parameter matches where the content actually lives
Example fix
// before
const data = await seFetch(url);
const items = ensureItems(data, 'stack exchange search');
// after
let items;
try {
items = ensureItems(data, 'stack exchange search');
} catch (e) {
if (e instanceof EmptyResultError) items = [];
else throw e;
} Defensive patterns
Strategy: validation
Validate before calling
const data = await seFetch(url);
if (!Array.isArray(data?.items) || data.items.length === 0) {
// treat as empty result up front
} Type guard
function hasItems(d) {
return Array.isArray(d?.items) && d.items.length > 0;
} Try / catch
try {
const items = ensureItems(data, 'search');
} catch (e) {
if (e instanceof EmptyResultError) return []; // expected empty
throw e;
} Prevention
- Check the query for typos before calling
- Confirm the entity exists on the queried site
- Treat EmptyResultError as an expected empty state, not a crash
- Test with a known-good query to separate input problems from API problems
When it happens
Trigger: Search/query matched nothing: e.g. search with a term that has no matches, user/reputation lookups for a nonexistent id, or filters that exclude all results.
Common situations: Misspelled search terms or usernames, querying a wrong site where the item does not exist, deleted/closed questions no longer returned by the API.
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
- rest-countries country
- No user message found in request
- No recent papers in ${category}. Check the category name.
- 获取到的视频播放信息对象不符合预期格式
- Bilibili view API returned a malformed ${label}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/2211ad10227c0c4f.
Report an issue: GitHub.