{"record":{"id":"35a78d9bc259cf3a","repo":"jackwener/OpenCLI","slug":"label-request-failed-err-message-err-35a78d","errorCode":null,"errorMessage":"${label} request failed: ${err?.message ?? err}","messagePattern":"(.+?) request failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/tvmaze/utils.js","lineNumber":46,"sourceCode":"export function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\n    const raw = value ?? defaultValue;\n    const n = typeof raw === 'number' ? raw : Number(raw);\n    if (!Number.isInteger(n) || n <= 0) {\n        throw new ArgumentError(`tvmaze ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`tvmaze ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport async function tvmazeFetch(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 api.tvmaze.com is reachable from this network.',\n        );\n    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `TVmaze returned 404 for ${url}.`);\n    }\n    if (resp.status === 429) {\n        throw new CommandExecutionError(\n            `${label} returned HTTP 429 (rate limited)`,\n            'TVmaze caps unauthenticated traffic at ~20 req/10s; 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":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/tvmaze/utils.js#L28-L64","documentation":"tvmazeFetch wraps the underlying fetch() call and converts network-level failures into CommandExecutionError with remediation advice. This error means the request to api.tvmaze.com never completed — DNS, TCP, TLS, or connection failure — not that the API returned an error status.","triggerScenarios":"fetch() throws for the request to api.tvmaze.com: DNS resolution failure, no network route, connection refused/timeout, TLS error, or a proxy blocking the request.","commonSituations":"Working offline or on a captive-portal Wi-Fi, corporate firewall/VPN blocking the host, DNS misconfiguration, or api.tvmaze.com outage.","solutions":["Verify network connectivity and that api.tvmaze.com resolves and is reachable (curl -v https://api.tvmaze.com/shows/1)","Check proxy/VPN/firewall settings; set HTTPS_PROXY if your environment requires one","Retry after a short wait in case of a transient outage","Read err.message in the error text — it names the underlying cause (ENOTFOUND, ECONNREFUSED, timeout, etc.)"],"exampleFix":"// before (no handling, hard crash)\nawait tvmazeFetch(url, 'shows');\n// after\ntry { await tvmazeFetch(url, 'shows'); }\ncatch (e) { console.error('TVmaze unreachable, check network:', e.message); process.exitCode = 1; }","handlingStrategy":"retry","validationCode":"import { lookup } from 'node:dns/promises';\nasync function canReachTvmaze() {\n  try { await lookup('api.tvmaze.com'); return true; }\n  catch { return false;\n  }\n}\n// gate the call: if (!(await canReachTvmaze())) { console.error('TVmaze unreachable'); }","typeGuard":"function isNetworkError(err) {\n  return err && (err.cause?.code === 'ENOTFOUND' ||\n    err.cause?.code === 'ECONNREFUSED' ||\n    err.cause?.code === 'ECONNRESET' ||\n    /request failed/.test(String(err.message)));\n}","tryCatchPattern":"try {\n  const data = await tvmazeFetch(url, 'shows');\n} catch (err) {\n  if (/request failed/.test(err.message)) {\n    console.error('Network problem reaching TVmaze:', err.message);\n    // optional: retry with backoff\n  } else throw err;\n}","preventionTips":["Wrap tvmazeFetch calls in try/catch and treat 'request failed' as a network problem","Add retry with exponential backoff for transient failures","Verify DNS/proxy/VPN configuration in restricted environments","Cache API responses to reduce dependence on connectivity"],"tags":["network","fetch","dns","connectivity"],"backgroundTag":"connection-refused","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}