{"record":{"id":"b44d780a54671bb3","repo":"jackwener/OpenCLI","slug":"wikipedia-page-request-failed-error-message","errorCode":null,"errorMessage":"wikipedia page request failed: ${error?.message || error}","messagePattern":"wikipedia page request failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/wikipedia/page.js","lineNumber":60,"sourceCode":"        url.searchParams.set('action', 'query');\n        url.searchParams.set('format', 'json');\n        url.searchParams.set('formatversion', '2');\n        url.searchParams.set('prop', 'extracts|info|description');\n        url.searchParams.set('inprop', 'url');\n        url.searchParams.set('explaintext', '1');\n        url.searchParams.set('redirects', '1');\n        url.searchParams.set('titles', title);\n\n        let resp;\n        try {\n            resp = await fetch(url, {\n                headers: {\n                    'User-Agent': 'opencli/1.0 (+https://github.com/jackwener/opencli)',\n                    'Accept': 'application/json',\n                },\n            });\n        } catch (error) {\n            throw new CommandExecutionError(`wikipedia page request failed: ${error?.message || error}`);\n        }\n        if (!resp.ok) {\n            throw new CommandExecutionError(`wikipedia page failed: HTTP ${resp.status}`);\n        }\n        let data;\n        try {\n            data = await resp.json();\n        } catch (error) {\n            throw new CommandExecutionError(`wikipedia returned malformed JSON: ${error?.message || error}`);\n        }\n        if (data?.error) {\n            throw new CommandExecutionError(`wikipedia API error: ${data.error.info || data.error.code}`);\n        }\n        const pages = Array.isArray(data?.query?.pages) ? data.query.pages : [];\n        const page = pages[0];\n        if (!page || page.missing) {\n            throw new EmptyResultError('wikipedia page', `No article \"${title}\" on ${lang}.wikipedia.org. Try \\`opencli wikipedia search\\` first.`);\n        }","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/wikipedia/page.js#L42-L78","documentation":"fetch() throws on network-level failures (DNS, TCP, TLS, aborts), and page.js wraps that in a CommandExecutionError prefixed 'wikipedia page request failed:'. This fires before any HTTP status is examined — the request never completed.","triggerScenarios":"No internet connection or DNS failure resolving <lang>.wikipedia.org; TLS interception/firewall blocking the request; a typo'd lang creating an invalid hostname that fails DNS; Node < 18 where global fetch is undefined (TypeError caught here).","commonSituations":"Offline development or CI without network egress; corporate proxies rejecting the request; using an invalid lang that produces a nonexistent subdomain; running on an old runtime without fetch.","solutions":["Check network connectivity and DNS resolution of en.wikipedia.org","Fix the lang value so the hostname is a real Wikipedia subdomain","Verify proxy/firewall allows HTTPS to wikipedia.org and set HTTPS_PROXY if needed","Upgrade to Node 18+ (or a runtime with global fetch) if fetch is undefined"],"exampleFix":"// before\nawait run(['wikipedia', 'page', title, '--lang', 'english']); // bad hostname, DNS fails\n// after\nawait run(['wikipedia', 'page', title, '--lang', 'en']);","handlingStrategy":"try-catch","validationCode":"// pre-flight reachability check\nconst online = await fetch('https://en.wikipedia.org/w/api.php?action=query&format=json', { method: 'HEAD' }).then(r => r.ok).catch(() => false);\nif (!online) throw new Error('wikipedia.org unreachable from this network');","typeGuard":null,"tryCatchPattern":"try {\n  return await pageCommand(args);\n} catch (err) {\n  if (err instanceof CommandExecutionError && err.message.includes('request failed')) {\n    console.error('network problem reaching wikipedia.org — check connectivity/proxy/DNS');\n    return null;\n  }\n  throw err;\n}","preventionTips":["Check connectivity/DNS before batch runs","Use a valid lang code so the subdomain exists","Configure HTTPS_PROXY for corporate networks","Run on Node 18+ (or another runtime with global fetch)"],"tags":["network","fetch-error","wikipedia","dns"],"backgroundTag":"fetch-network-error","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}