{"record":{"id":"504a76d76de359f6","repo":"jackwener/OpenCLI","slug":"hf-models-request-failed-error-message-erro","errorCode":null,"errorMessage":"hf models request failed: ${error?.message || error}","messagePattern":"hf models request failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/hf/models.js","lineNumber":58,"sourceCode":"\n        const url = new URL('https://huggingface.co/api/models');\n        url.searchParams.set('sort', sort);\n        url.searchParams.set('direction', '-1');\n        url.searchParams.set('limit', String(limit));\n        url.searchParams.set('full', 'true');\n        if (args.search) url.searchParams.set('search', String(args.search));\n        if (args.pipeline) url.searchParams.set('pipeline_tag', String(args.pipeline));\n\n        let resp;\n        try {\n            resp = await fetch(url, {\n                headers: {\n                    'Accept': 'application/json',\n                    'User-Agent': 'opencli/1.0 (+https://github.com/jackwener/opencli)',\n                },\n            });\n        } catch (error) {\n            throw new CommandExecutionError(`hf models request failed: ${error?.message || error}`);\n        }\n        if (!resp.ok) {\n            throw new CommandExecutionError(`hf models failed: HTTP ${resp.status}`);\n        }\n        let data;\n        try {\n            data = await resp.json();\n        } catch (error) {\n            throw new CommandExecutionError(`hf models returned malformed JSON: ${error?.message || error}`);\n        }\n        const list = Array.isArray(data) ? data : [];\n        if (list.length === 0) {\n            throw new EmptyResultError('hf models', 'No matching models on huggingface.co.');\n        }\n        return list.slice(0, limit).map((m, i) => {\n            const id = m.id || m.modelId || '';\n            const slashIdx = id.indexOf('/');\n            const author = slashIdx > 0 ? id.slice(0, slashIdx) : '';","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hf/models.js#L40-L76","documentation":"CommandExecutionError thrown at clis/hf/models.js:58 when the fetch() call to https://huggingface.co/api/models itself rejects — i.e. the HTTP exchange never completed (DNS failure, connection refused/reset, TLS error, timeout, offline). The library wraps the raw cause (error?.message || error) so the original failure reason is preserved in the message.","triggerScenarios":"Any network-level failure during `await fetch(url, {...})` in the `hf models` command: no internet connection, DNS resolution failure for huggingface.co, firewall/proxy blocking outbound HTTPS, TLS interception errors, or process-level network restrictions.","commonSituations":"Working offline or on a captive-portal Wi-Fi; corporate proxy requiring configuration not honored by the fetch runtime; DNS blocked for huggingface.co in restricted regions; IPv6 misconfiguration; a container with no egress.","solutions":["Verify basic connectivity: curl -sS 'https://huggingface.co/api/models?limit=1' and compare the error.","Check proxy/VPN settings and, if behind a corporate proxy, configure HTTPS_PROXY for the runtime.","Retry after confirming DNS works (nslookup huggingface.co); transient outages resolve on retry with backoff.","Note that models.js hardcodes the URL — HF_ENDPOINT is only honored by paper.js; changing the endpoint requires editing clis/hf/models.js."],"exampleFix":"// before\nresp = await fetch(url, { headers: { Accept: 'application/json', ... } });\n// after (caller-side guard in a wrapper script)\ntry {\n  const r = await fetch('https://huggingface.co/api/models?limit=1');\n  if (!r.ok) throw new Error('HF unreachable: ' + r.status);\n} catch (e) { console.error('Check network/proxy before running hf models:', e.message); }","handlingStrategy":"retry","validationCode":"// Reachability probe before running the command\nconst probe = await fetch('https://huggingface.co/api/models?limit=1').then(r => r.ok).catch(() => false);\nif (!probe) console.error('huggingface.co unreachable — check network/proxy/DNS before running hf models');","typeGuard":null,"tryCatchPattern":"async function runWithRetry(cmd, attempts = 3) {\n  for (let i = 1; i <= attempts; i++) {\n    try { return await run(cmd); }\n    catch (e) {\n      if (!String(e.message).includes('request failed') || i === attempts) throw e;\n      await new Promise(r => setTimeout(r, 2 ** i * 500)); // backoff: 500ms, 1s, 2s\n    }\n  }\n}","preventionTips":["Verify egress to huggingface.co (curl the API) before scripted runs.","Configure HTTPS_PROXY/VPN correctly in restricted networks.","Add exponential-backoff retries for transient network errors.","Confirm DNS resolves huggingface.co in containers/CI."],"tags":["network","fetch","huggingface","connectivity"],"backgroundTag":"network-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}