{"record":{"id":"4a8785a2e054125c","repo":"jackwener/OpenCLI","slug":"label-request-failed-err-message-err-4a8785","errorCode":null,"errorMessage":"${label} request failed: ${err?.message ?? err}","messagePattern":"(.+?) request failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/pypi/utils.js","lineNumber":30,"sourceCode":"export function requirePackageName(value) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError('pypi package name is required (e.g. \"requests\", \"pandas\")');\n    if (!PKG_NAME.test(s)) {\n        throw new ArgumentError(\n            `pypi package name \"${value}\" is not a valid distribution name`,\n            'PyPI accepts ASCII letters / digits / \"._-\" with no leading or trailing separator.',\n        );\n    }\n    return s;\n}\n\nexport async function pypiFetch(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 pypi.org / pypistats.org are reachable from this network.',\n        );\n    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `PyPI returned 404 for ${url}.`);\n    }\n    if (resp.status === 429) {\n        throw new CommandExecutionError(\n            `${label} returned HTTP 429 (rate limited)`,\n            'PyPI throttles unauthenticated bursts; wait a few seconds and retry.',\n        );\n    }\n    if (!resp.ok) {\n        throw new CommandExecutionError(`${label} returned HTTP ${resp.status}`);\n    }\n    let body;\n    try {","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/pypi/utils.js#L12-L48","documentation":"CommandExecutionError thrown by pypiFetch when the underlying fetch itself rejects — i.e. the request never got an HTTP response. The label identifies which call (e.g. 'pypi package <name>') failed, and the original error message is appended.","triggerScenarios":"Any pypiFetch call where DNS resolution fails, the connection is refused/times out, TLS fails, or the process lacks network access to pypi.org or pypistats.org.","commonSituations":"Working offline or on a flaky network; corporate firewalls blocking pypi.org; misconfigured proxy environment variables; DNS outages; IPv6-only environments.","solutions":["Check basic connectivity: curl -I https://pypi.org","Check proxy env vars (HTTP_PROXY/HTTPS_PROXY) are correct if behind a proxy","Retry after transient network issues; add retry/backoff around CLI calls","Verify DNS resolves pypi.org (nslookup pypi.org)"],"exampleFix":"// before\nconst data = await pypiFetch(url, 'pypi pkg'); // throws on network blip\n// after\nlet data;\nfor (let i = 0; i < 3; i++) {\n  try { data = await pypiFetch(url, 'pypi pkg'); break; }\n  catch (e) { if (i === 2) throw e; await new Promise(r => setTimeout(r, 2 ** i * 500)); }\n}","handlingStrategy":"retry","validationCode":"// pre-check reachability\nconst ok = await fetch('https://pypi.org/simple/', { method: 'HEAD' }).then(r => r.ok).catch(() => false);\nif (!ok) throw new Error('pypi.org unreachable from this network');","typeGuard":"null","tryCatchPattern":"async function fetchWithRetry(url, label, tries = 3) {\n  for (let i = 0; ; i++) {\n    try { return await pypiFetch(url, label); }\n    catch (e) {\n      if (i >= tries - 1 || !/request failed/i.test(e.message)) throw e;\n      await new Promise(r => setTimeout(r, 2 ** i * 500));\n    }\n  }\n}","preventionTips":["Check proxy env vars (HTTP_PROXY/HTTPS_PROXY/NO_PROXY) before running","Prefer wired/stable networks for CI jobs hitting PyPI","Add exponential backoff on network errors in batch scripts"],"tags":["pypi","network","fetch"],"backgroundTag":"connection-refused","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}