jackwener/OpenCLI · error · CommandExecutionError
hf models request failed: ${error?.message || error}
Error message
hf models request failed: ${error?.message || error} What it means
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.
Source
Thrown at clis/hf/models.js:58
const url = new URL('https://huggingface.co/api/models');
url.searchParams.set('sort', sort);
url.searchParams.set('direction', '-1');
url.searchParams.set('limit', String(limit));
url.searchParams.set('full', 'true');
if (args.search) url.searchParams.set('search', String(args.search));
if (args.pipeline) url.searchParams.set('pipeline_tag', String(args.pipeline));
let resp;
try {
resp = await fetch(url, {
headers: {
'Accept': 'application/json',
'User-Agent': 'opencli/1.0 (+https://github.com/jackwener/opencli)',
},
});
} catch (error) {
throw new CommandExecutionError(`hf models request failed: ${error?.message || error}`);
}
if (!resp.ok) {
throw new CommandExecutionError(`hf models failed: HTTP ${resp.status}`);
}
let data;
try {
data = await resp.json();
} catch (error) {
throw new CommandExecutionError(`hf models returned malformed JSON: ${error?.message || error}`);
}
const list = Array.isArray(data) ? data : [];
if (list.length === 0) {
throw new EmptyResultError('hf models', 'No matching models on huggingface.co.');
}
return list.slice(0, limit).map((m, i) => {
const id = m.id || m.modelId || '';
const slashIdx = id.indexOf('/');
const author = slashIdx > 0 ? id.slice(0, slashIdx) : '';View on GitHub (pinned to 49907e53dc)
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.
Example fix
// before
resp = await fetch(url, { headers: { Accept: 'application/json', ... } });
// after (caller-side guard in a wrapper script)
try {
const r = await fetch('https://huggingface.co/api/models?limit=1');
if (!r.ok) throw new Error('HF unreachable: ' + r.status);
} catch (e) { console.error('Check network/proxy before running hf models:', e.message); } Defensive patterns
Strategy: retry
Validate before calling
// Reachability probe before running the command
const probe = await fetch('https://huggingface.co/api/models?limit=1').then(r => r.ok).catch(() => false);
if (!probe) console.error('huggingface.co unreachable — check network/proxy/DNS before running hf models'); Try / catch
async function runWithRetry(cmd, attempts = 3) {
for (let i = 1; i <= attempts; i++) {
try { return await run(cmd); }
catch (e) {
if (!String(e.message).includes('request failed') || i === attempts) throw e;
await new Promise(r => setTimeout(r, 2 ** i * 500)); // backoff: 500ms, 1s, 2s
}
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- coingecko derivatives request failed: ${err?.message ?? err}
- dongchedi ${contextHint} network error: ${err?.message || er
- `${label} request failed: ${err?.message ?? err}`
- hf datasets request failed: ${error?.message || error}
- hf paper request failed: ${err?.message ?? err}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/504a76d76de359f6.
Report an issue: GitHub.