jackwener/OpenCLI · warning · EmptyResultError

${label} not found

Error message

${label} not found

What it means

After the network request succeeds, fetchJson checks res.status === 404 and throws an EmptyResultError with the human-readable label. The Stack Exchange API answered, but the specific resource (question, answer, or comment set) does not exist or was not returned. It is an intentional 'nothing found' signal used by callers to render empty output rather than a crash.

Source

Thrown at clis/stackoverflow/read.js:41

import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';

const SE_API_BASE = 'https://api.stackexchange.com/2.3';
const SE_SITE = 'stackoverflow';
const SE_MAX_PAGE_SIZE = 100;

async function fetchJson(url, label) {
    let res;
    try {
        res = await fetch(url);
    } catch (e) {
        const detail = e instanceof Error ? e.message : String(e);
        throw new CommandExecutionError(
            `Network failure fetching ${label}: ${detail}`,
            'Check connectivity to api.stackexchange.com',
        );
    }
    if (res.status === 404) {
        throw new EmptyResultError(label, `${label} not found`);
    }
    if (!res.ok) {
        throw new CommandExecutionError(
            `Stack Exchange API HTTP ${res.status} for ${label}`,
            'Check the question id and quota (300/day per IP)',
        );
    }
    let json;
    try {
        json = await res.json();
    } catch (e) {
        const detail = e instanceof Error ? e.message : String(e);
        throw new CommandExecutionError(
            `Malformed JSON from Stack Exchange API for ${label}: ${detail}`,
            'The API returned a non-JSON body — likely a transient outage',
        );
    }
    if (json && json.error_id) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify the question/answer id exists by opening stackoverflow.com/q/<id> in a browser
  2. Confirm the id came from stackoverflow.com and not another Stack Exchange site
  3. Re-extract the numeric id from the full URL (the digits before the slug)
  4. If the question was deleted/merged, find its new id from the redirect page and retry

Example fix

// before
await readQuestion('58261800-slug');

// after
await readQuestion('58261800');
Defensive patterns

Strategy: validation

Validate before calling

function assertValidStackExchangeId(id, kind = 'question') {
  const n = Number(String(id).trim());
  if (!Number.isInteger(n) || n <= 0) {
    throw new TypeError(`${kind} id must be a positive integer, got: ${id}`);
  }
  return n;
}
// call before: assertValidStackExchangeId(extractIdFromUrl(url));

Type guard

function isValidStackExchangeId(id) {
  return typeof id === 'string'
    ? /^\d+$/.test(id.trim())
    : Number.isInteger(id) && id > 0;
}

Try / catch

import { EmptyResultError } from '@jackwener/opencli/errors';

try {
  const q = await qData(id);
} catch (e) {
  if (e instanceof EmptyResultError) {
    console.warn(`Skipping ${label}: not found or deleted`);
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: Calling qData with a question id that does not exist or was deleted; ansData/ansCommentsData/answersData with an answer id belonging to another (or deleted) question; passing a URL-extracted id that is actually a slug or truncated number; hitting a 404 because the site filter scoping excludes the item.

Common situations: Copy-pasting a question id from a different Stack Exchange site (e.g. Server Fault) while the CLI queries stackoverflow; id taken from a redirecting/merged question that now 404s; typo'd or partially copied id from a URL; question deleted by moderators after the script was written.

Related errors


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