jackwener/OpenCLI · warning · EmptyResultError

wikidata entity: Wikidata entity ${qid} returned no payload.

Error message

wikidata entity: Wikidata entity ${qid} returned no payload.

What it means

The wikidata entity command fetches Special:EntityData/<qid>.json and expects body.entities[qid] to exist. If Wikidata responds successfully but the payload has no entry for the requested QID, the adapter raises an EmptyResultError with this message. It signals 'the request was valid but Wikidata returned nothing for this entity' rather than a network or argument failure.

Source

Thrown at clis/wikidata/entity.js:42

        'qid',
        'type',
        'label',
        'description',
        'aliases',
        'claimPropertyCount',
        'sitelinkCount',
        'enwikiTitle',
        'modified',
        'url',
    ],
    func: async (args) => {
        const qid = requireEntityId(args.id);
        const language = requireLanguage(args.language);
        const url = `${WIKIDATA_BASE}/wiki/Special:EntityData/${encodeURIComponent(qid)}.json`;
        const body = await wikidataFetch(url, 'wikidata entity');
        const entity = body?.entities?.[qid];
        if (!entity) {
            throw new EmptyResultError('wikidata entity', `Wikidata entity ${qid} returned no payload.`);
        }
        const claims = entity.claims && typeof entity.claims === 'object' ? entity.claims : {};
        const sitelinks = entity.sitelinks && typeof entity.sitelinks === 'object' ? entity.sitelinks : {};
        const enwiki = sitelinks?.enwiki?.title;
        return [{
            qid,
            type: typeof entity.type === 'string' ? entity.type : null,
            label: pickLocalised(entity.labels, language),
            description: pickLocalised(entity.descriptions, language),
            aliases: joinAliases(entity.aliases, language),
            claimPropertyCount: Object.keys(claims).length,
            sitelinkCount: Object.keys(sitelinks).length,
            enwikiTitle: typeof enwiki === 'string' && enwiki.trim() ? enwiki : null,
            modified: typeof entity.modified === 'string' ? entity.modified : null,
            url: `${WIKIDATA_BASE}/wiki/${qid}`,
        }];
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify the entity exists by opening https://www.wikidata.org/wiki/<qid> in a browser — if it redirects, use the target QID
  2. Re-run `wikidata search` to find the correct current QID
  3. If the entity was merged, re-run against the merged-in QID
  4. Retry later if Wikidata is having a partial outage

Example fix

// before
const [entity] = await runCli(['wikidata', 'entity', 'Q999999999']);
// after
const [search] = await runCli(['wikidata', 'search', 'Douglas Adams']);
const [entity] = await runCli(['wikidata', 'entity', search.qid]);
Defensive patterns

Strategy: try-catch

Validate before calling

// verify the QID resolves before use
const res = await fetch(`https://www.wikidata.org/wiki/Special:EntityData/${qid}.json`);
if (res.ok && !Object.keys((await res.json())?.entities ?? {}).length) console.warn('no payload for', qid);

Type guard

function hasEntityPayload(body, qid) { return Boolean(body?.entities?.[qid]); }

Try / catch

try {
    const [entity] = await runCli(['wikidata', 'entity', qid]);
} catch (e) {
    if (/returned no payload/.test(e.message)) {
        // fall back to a search to find the current/merged QID
    } else throw e;
}

Prevention

When it happens

Trigger: Calling `wikidata entity <qid>` where the response body.entities lacks the requested qid key — e.g. a deleted/redirected entity, or a malformed response despite HTTP 200.

Common situations: Querying a QID that has been deleted or merged into another entity on Wikidata; a typo in the ID that still matches the Q\d+ pattern (e.g. an unused Q number); Wikidata returning an empty entities object during partial outages.

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/a0e5efc22b665760. Report an issue: GitHub.