{"record":{"id":"acf4d8382717d49c","repo":"jackwener/OpenCLI","slug":"label-request-failed-err-message-err-acf4d8","errorCode":null,"errorMessage":"${label} request failed: ${err?.message ?? err}","messagePattern":"(.+?) request failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/wikidata/utils.js","lineNumber":67,"sourceCode":"export function requireLanguage(value, defaultValue = 'en') {\n    const raw = String(value ?? defaultValue).trim().toLowerCase();\n    // Wikidata language codes are 2-3 letter ISO 639 codes plus optional region (`zh-hans`).\n    if (!/^[a-z]{2,3}(-[a-z]{2,8})?$/.test(raw)) {\n        throw new ArgumentError(\n            `wikidata language \"${value}\" is not a valid language code`,\n            'Expected an ISO 639 language code such as \"en\", \"fr\", \"zh\", \"zh-hans\".',\n        );\n    }\n    return raw;\n}\n\nexport async function wikidataFetch(url, label) {\n    let resp;\n    try {\n        resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });\n    }\n    catch (err) {\n        throw new CommandExecutionError(\n            `${label} request failed: ${err?.message ?? err}`,\n            'Check that www.wikidata.org is reachable from this network.',\n        );\n    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `Wikidata returned 404 for ${url}.`);\n    }\n    if (resp.status === 429) {\n        throw new CommandExecutionError(\n            `${label} returned HTTP 429 (rate limited)`,\n            'Wikidata throttles anonymous traffic; back off and retry.',\n        );\n    }\n    if (!resp.ok) {\n        throw new CommandExecutionError(`${label} returned HTTP ${resp.status}`);\n    }\n    let body;\n    try {","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/wikidata/utils.js#L49-L85","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check basic connectivity: curl -I https://www.wikidata.org from the same machine","If behind a corporate proxy, set HTTPS_PROXY/HTTP_PROXY so Node's fetch can route through it","Verify DNS resolves www.wikidata.org (nslookup/ping)","Reconnect VPN or retry once network access is restored","If wikidata.org is down, wait and retry — check Wikimedia status pages"],"exampleFix":"// before\nconst body = await wikidataFetch(url, 'wikidata entity'); // throws if offline\n// after\nlet body;\ntry {\n    body = await wikidataFetch(url, 'wikidata entity');\n} catch (e) {\n    if (/request failed/.test(e.message)) {\n        await new Promise(r => setTimeout(r, 2000));\n        body = await wikidataFetch(url, 'wikidata entity');\n    } else throw e;\n}","handlingStrategy":"retry","validationCode":"// reachability pre-check\nconst head = await fetch('https://www.wikidata.org/w/api.php', { method: 'HEAD' }).catch(() => null);\nif (!head) throw new Error('www.wikidata.org is unreachable from this network');","typeGuard":"function isNetworkError(err) { return err instanceof Error && /fetch failed|ENOTFOUND|ECONNREFUSED|EAI_AGAIN|certificate/i.test(String(err.cause ?? err.message)); }","tryCatchPattern":"async function fetchWithRetry(url, label, attempts = 3) {\n    for (let i = 0; i < attempts; i++) {\n        try { return await wikidataFetch(url, label); }\n        catch (e) {\n            if (isNetworkError(e) && i < attempts - 1) {\n                await new Promise(r => setTimeout(r, 1000 * 2 ** i));\n                continue;\n            }\n            throw e;\n        }\n    }\n}","preventionTips":["Verify proxy env vars (HTTPS_PROXY) in CI/containers","Check VPN/DNS before batch runs against wikidata.org","Add exponential-backoff retries for transient network failures","Monitor Wikimedia status for outages before large jobs","Set a timeout on fetches so hangs fail fast and retry"],"tags":["network","connectivity","fetch"],"backgroundTag":"connection-refused","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}