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 = {
    '&amp;': '&', '&lt;': '<', '&gt;': '>', '&quot;': '"',
    '&#39;': "'", '&apos;': "'", '&nbsp;': ' ',
};

/**
 * Decode the small set of HTML entities Stack Exchange emits in display
 * names and titles (e.g. "Jon Skeet&#39;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

  1. Loosen the search term or remove filters and retry
  2. Confirm the target entity exists on the site queried (correct site, correct id)
  3. Handle EmptyResultError in the caller as an expected empty state
  4. 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

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


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