{"record":{"id":"959c0d6a0909e2b8","repo":"jackwener/OpenCLI","slug":"label-request-failed","errorCode":null,"errorMessage":"${label} request failed","messagePattern":"(.+?) request failed","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/pubmed/utils.js","lineNumber":103,"sourceCode":"    const delayMs = process.env.NCBI_API_KEY ? 110 : 360;\n    const now = Date.now();\n    const waitMs = Math.max(0, lastRequestAt + delayMs - now);\n    if (waitMs > 0) {\n        await new Promise(resolve => setTimeout(resolve, waitMs));\n    }\n    lastRequestAt = Date.now();\n}\n\nexport async function eutilsFetch(tool, params = {}, { retmode = 'json', label = 'PubMed E-utilities' } = {}) {\n    const url = buildEutilsUrl(tool, { ...params, retmode });\n    await waitForRateLimit();\n    let response;\n    try {\n        response = await fetch(url);\n    }\n    catch (error) {\n        const detail = error instanceof Error ? error.message : String(error);\n        throw new CommandExecutionError(`${label} request failed`, detail);\n    }\n    if (!response.ok) {\n        throw new CommandExecutionError(`${label} HTTP ${response.status}`, 'Check NCBI availability, request parameters, and optional NCBI_API_KEY.');\n    }\n    if (retmode === 'xml') {\n        return response.text();\n    }\n    try {\n        const json = await response.json();\n        assertNoEutilsError(json, label);\n        return json;\n    }\n    catch (error) {\n        if (error instanceof CommandExecutionError) {\n            throw error;\n        }\n        const detail = error instanceof Error ? error.message : String(error);\n        throw new CommandExecutionError(`${label} returned invalid JSON`, detail);","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/pubmed/utils.js#L85-L121","documentation":"eutilsFetch performs the HTTP GET to NCBI E-utilities. When fetch itself rejects (network unreachable, DNS failure, connection refused, TLS error), it rethrows as CommandExecutionError '<label> request failed' with the underlying error message as detail. Called by the xml, esearch, and result code paths.","triggerScenarios":"Any pubmed command while offline, with broken DNS, through a blocking proxy/firewall, or when NCBI drops the connection mid-request.","commonSituations":"Corporate proxies blocking ncbi.nlm.nih.gov, VPN down, missing HTTPS_PROXY for Node's fetch, transient NCBI outage, IPv6 connectivity issues.","solutions":["Verify connectivity: curl -v https://eutils.ncbi.nlm.nih.gov/entrez/eutils/einfo.fcgi","Set HTTPS_PROXY/HTTP_PROXY (and NO_PROXY) if your network requires a proxy","Retry after a short backoff — failures are often transient","Check NCBI service status and network/firewall rules for eutils.ncbi.nlm.nih.gov"],"exampleFix":"// before\nHTTPS_PROXY=  # proxy required by network but unset\npubmed search 'cattle genomics'\n// after\nexport HTTPS_PROXY=http://proxy.corp.example:8080\npubmed search 'cattle genomics'","handlingStrategy":"retry","validationCode":"// pre-check connectivity before running the command\nawait fetch('https://eutils.ncbi.nlm.nih.gov/entrez/eutils/einfo.fcgi')\n  .then(r => { if (!r.ok) throw new Error('eutils unreachable: ' + r.status); });","typeGuard":null,"tryCatchPattern":"async function withRetry(fn, attempts = 3) {\n  for (let i = 1; i <= attempts; i++) {\n    try { return await fn(); }\n    catch (err) {\n      if (err instanceof CommandExecutionError && /request failed/.test(err.message) && i < attempts) {\n        await new Promise(r => setTimeout(r, 2 ** i * 500));\n        continue;\n      }\n      throw err;\n    }\n  }\n}\n// usage: withRetry(() => pubmedSearch(query))","preventionTips":["Verify network/proxy access to eutils.ncbi.nlm.nih.gov before batch runs","Set HTTPS_PROXY/HTTP_PROXY env vars when behind a corporate proxy","Wrap calls in exponential-backoff retry for transient failures","Monitor NCBI status during long-running jobs"],"tags":["network","http-request","ncbi","eutils"],"backgroundTag":"network-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}