jackwener/OpenCLI · warning · EmptyResultError
Wikidata returned 404 for ${url}.
Error message
Wikidata returned 404 for ${url}. What it means
wikidataFetch wraps every Wikidata HTTP call. A 404 from the Wikidata API is treated as an EmptyResultError rather than a hard failure, because 404 here means 'entity/URL does not exist' — most commonly a bad Q-ID on Special:EntityData. The library throws it so callers can treat 'not found' as an empty result instead of an error.
Source
Thrown at clis/wikidata/utils.js:73
'Expected an ISO 639 language code such as "en", "fr", "zh", "zh-hans".',
);
}
return raw;
}
export async function wikidataFetch(url, label) {
let resp;
try {
resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });
}
catch (err) {
throw new CommandExecutionError(
`${label} request failed: ${err?.message ?? err}`,
'Check that www.wikidata.org is reachable from this network.',
);
}
if (resp.status === 404) {
throw new EmptyResultError(label, `Wikidata returned 404 for ${url}.`);
}
if (resp.status === 429) {
throw new CommandExecutionError(
`${label} returned HTTP 429 (rate limited)`,
'Wikidata throttles anonymous traffic; back off and retry.',
);
}
if (!resp.ok) {
throw new CommandExecutionError(`${label} returned HTTP ${resp.status}`);
}
let body;
try {
body = await resp.json();
}
catch (err) {
throw new CommandExecutionError(`${label} returned malformed JSON: ${err?.message ?? err}`);
}
return body;View on GitHub (pinned to 49907e53dc)
Solutions
- Verify the entity ID is a valid existing Q/P/L ID by searching it on www.wikidata.org or via wbsearchentities
- Catch EmptyResultError in the calling code and treat it as 'no result' rather than a crash
- Check the URL passed to wikidataFetch for typos in the path or hostname
Example fix
// before
const body = await wikidataFetch(`${WIKIDATA_BASE}/wiki/Special:EntityData/${qid}.json`, 'entity');
// after
let body;
try {
body = await wikidataFetch(`${WIKIDATA_BASE}/wiki/Special:EntityData/${qid}.json`, 'entity');
} catch (err) {
if (err instanceof EmptyResultError) return null; // entity not found
throw err;
} Defensive patterns
Strategy: try-catch
Validate before calling
const qid = String(id ?? '').trim().toUpperCase();
if (!/^[QPL]\d+$/.test(qid)) throw new Error(`invalid entity id: ${id}`); Type guard
function isEntityId(v) { return typeof v === 'string' && /^[QPL]\d+$/.test(v.trim().toUpperCase()); } Try / catch
try {
const body = await wikidataFetch(url, 'entity');
} catch (err) {
if (err instanceof EmptyResultError) return null; // 404 = entity not found
throw err;
} Prevention
- Validate Q/P/L IDs with /^[QPL]\d+$/ before building the URL
- Resolve possibly-stale IDs via wbsearchentities first
- Treat EmptyResultError as an expected 'no result' outcome, not a crash
When it happens
Trigger: Calling wikidataFetch with an entity URL like https://www.wikidata.org/wiki/Special:EntityData/Q999999999.json where the Q-ID does not exist; a mistyped or deleted entity ID reaching the endpoint; a wrong path/hostname in the URL passed to wikidataFetch.
Common situations: User pastes an invalid or deleted Wikidata Q-ID (e.g. off-by-one or fabricated ID); a script iterates a stale list of entities where some were merged/redirected and the old ID 404s; constructing the EntityData URL programmatically with a bad ID.
Related errors
- Chess.com returned 404 for ${url}
- coingecko has no coin with id "${id}".
- crates.io returned 404 for ${url}.
- dblp returned 404 — the requested record may not exist.
- hf datasets
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/43d7aaeb7beea29d.
Report an issue: GitHub.