{"record":{"id":"1c1567f8060efbcf","repo":"jackwener/OpenCLI","slug":"label-request-failed-err-message-err-1c1567","errorCode":null,"errorMessage":"${label} request failed: ${err?.message ?? err}","messagePattern":"(.+?) request failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"critical","filePath":"clis/packagist/utils.js","lineNumber":61,"sourceCode":"    }\n    const vendor = raw.slice(0, slash);\n    const pkg = raw.slice(slash + 1);\n    if (vendor.length > 100 || pkg.length > 100 || !SEGMENT.test(vendor) || !SEGMENT.test(pkg)) {\n        throw new ArgumentError(\n            `packagist package \"${value}\" is not a valid Composer name`,\n            'Use lowercase letters / digits / \"_-.\", segments separated by single \"_-.\" chars (max 100 chars each).',\n        );\n    }\n    return { vendor, package: pkg, full: `${vendor}/${pkg}` };\n}\n\nexport async function packagistFetch(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 packagist.org is reachable from this network.',\n        );\n    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `Packagist returned 404 for ${url}.`);\n    }\n    if (resp.status === 429) {\n        throw new CommandExecutionError(\n            `${label} returned HTTP 429 (rate limited)`,\n            'Packagist throttles 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":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/packagist/utils.js#L43-L79","documentation":"packagistFetch wraps the underlying fetch() call; when fetch itself rejects (network-level failure, not an HTTP error status), it rethrows as CommandExecutionError with this message plus the hint to check reachability of packagist.org. This indicates the request never got a response — DNS, TCP, TLS, or proxy failure.","triggerScenarios":"Calling body (which calls packagistFetch) while offline; DNS resolution failure for packagist.org; blocked egress firewall; invalid/crashing HTTP proxy from HTTPS_PROXY; TLS interception with an untrusted cert; Node fetch abort due to timeout.","commonSituations":"Corporate network blocking packagist.org; VPN required but not connected; typo'd PACKAGIST_BASE override in a custom build; container without network access; transient ISP outage.","solutions":["Check network connectivity: curl -I https://packagist.org and compare.","Verify DNS resolves packagist.org (nslookup/dig) and proxy env vars (HTTPS_PROXY) are correct.","Connect to the required VPN or whitelist packagist.org in the firewall.","Retry with backoff if the failure was transient.","Catch CommandExecutionError and surface the reachability hint to the user."],"exampleFix":"// before\nconst data = await body({ q: term }); // throws if offline\n\n// after\ntry {\n  const data = await body({ q: term });\n} catch (e) {\n  if (/request failed/.test(e.message)) {\n    console.error('packagist.org unreachable — check network/proxy');\n  }\n  throw e;\n}","handlingStrategy":"retry","validationCode":"async function canReachPackagist() {\n  try {\n    const r = await fetch('https://packagist.org', { method: 'HEAD' });\n    return r.ok || r.status < 500;\n  } catch { return false; }\n}\nif (!(await canReachPackagist())) throw new Error('packagist.org unreachable — check network/proxy/VPN');","typeGuard":"null","tryCatchPattern":"async function fetchWithRetry(fn, tries = 3) {\n  for (let i = 0; ; i++) {\n    try { return await fn(); }\n    catch (e) {\n      if (i >= tries || !/request failed/.test(e.message)) throw e;\n      await new Promise(r => setTimeout(r, 2 ** i * 1000));\n    }\n  }\n}","preventionTips":["Probe connectivity (curl/DNS) before batch operations against packagist.org.","Verify HTTPS_PROXY/HTTP_PROXY env vars when behind a corporate proxy.","Connect the required VPN before running network-dependent scripts.","Set a fetch timeout and retry transient network errors with exponential backoff."],"tags":["network","fetch","dns","connectivity","packagist"],"backgroundTag":"network-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}