jackwener/OpenCLI · error · CommandExecutionError

${label} request failed: ${err?.message ?? err}

Error message

${label} request failed: ${err?.message ?? err}

What it means

wikidataFetch wraps the underlying fetch call to www.wikidata.org. If fetch itself rejects — DNS failure, no network, TLS error, connection refused — the adapter converts the raw error into a CommandExecutionError with this message, preserving the original error text and advising a connectivity check. HTTP-level failures (404/429/other statuses) are handled separately after the fetch resolves.

Source

Thrown at clis/wikidata/utils.js:67

export function requireLanguage(value, defaultValue = 'en') {
    const raw = String(value ?? defaultValue).trim().toLowerCase();
    // Wikidata language codes are 2-3 letter ISO 639 codes plus optional region (`zh-hans`).
    if (!/^[a-z]{2,3}(-[a-z]{2,8})?$/.test(raw)) {
        throw new ArgumentError(
            `wikidata language "${value}" is not a valid language code`,
            '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 {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check basic connectivity: curl -I https://www.wikidata.org from the same machine
  2. If behind a corporate proxy, set HTTPS_PROXY/HTTP_PROXY so Node's fetch can route through it
  3. Verify DNS resolves www.wikidata.org (nslookup/ping)
  4. Reconnect VPN or retry once network access is restored
  5. If wikidata.org is down, wait and retry — check Wikimedia status pages

Example fix

// before
const body = await wikidataFetch(url, 'wikidata entity'); // throws if offline
// after
let body;
try {
    body = await wikidataFetch(url, 'wikidata entity');
} catch (e) {
    if (/request failed/.test(e.message)) {
        await new Promise(r => setTimeout(r, 2000));
        body = await wikidataFetch(url, 'wikidata entity');
    } else throw e;
}
Defensive patterns

Strategy: retry

Validate before calling

// reachability pre-check
const head = await fetch('https://www.wikidata.org/w/api.php', { method: 'HEAD' }).catch(() => null);
if (!head) throw new Error('www.wikidata.org is unreachable from this network');

Type guard

function isNetworkError(err) { return err instanceof Error && /fetch failed|ENOTFOUND|ECONNREFUSED|EAI_AGAIN|certificate/i.test(String(err.cause ?? err.message)); }

Try / catch

async function fetchWithRetry(url, label, attempts = 3) {
    for (let i = 0; i < attempts; i++) {
        try { return await wikidataFetch(url, label); }
        catch (e) {
            if (isNetworkError(e) && i < attempts - 1) {
                await new Promise(r => setTimeout(r, 1000 * 2 ** i));
                continue;
            }
            throw e;
        }
    }
}

Prevention

When it happens

Trigger: Any wikidata command (entity, search) when the network request to wikidata.org throws before a response is received: offline machine, DNS resolution failure for www.wikidata.org, firewall/proxy blocking the connection, or TLS interception failures.

Common situations: Running the CLI in a CI container or air-gapped environment without egress; corporate proxy requiring configuration that Node's fetch does not pick up; VPN down; DNS misconfiguration; Wikidata temporarily unreachable.

Related errors


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