jackwener/OpenCLI · error · CommandExecutionError

hf datasets request failed: ${error?.message || error}

Error message

hf datasets request failed: ${error?.message || error}

What it means

The fetch to https://huggingface.co/api/datasets threw (network-level failure), so the command wraps it in a CommandExecutionError with 'hf datasets request failed: ...' and the underlying error message. This is a transport failure, not an HTTP status error.

Source

Thrown at clis/hf/datasets.js:56

        }

        const url = new URL('https://huggingface.co/api/datasets');
        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));

        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 datasets request failed: ${error?.message || error}`);
        }
        if (!resp.ok) {
            throw new CommandExecutionError(`hf datasets failed: HTTP ${resp.status}`);
        }
        let data;
        try {
            data = await resp.json();
        } catch (error) {
            throw new CommandExecutionError(`hf datasets returned malformed JSON: ${error?.message || error}`);
        }
        const list = Array.isArray(data) ? data : [];
        if (list.length === 0) {
            throw new EmptyResultError('hf datasets', 'No matching datasets on huggingface.co.');
        }
        return list.slice(0, limit).map((d, i) => {
            const id = d.id || '';
            const slashIdx = id.indexOf('/');
            const author = slashIdx > 0 ? id.slice(0, slashIdx) : '';

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check network connectivity and that huggingface.co is reachable (curl https://huggingface.co/api/datasets)
  2. Read the underlying message after 'request failed:' for the specific cause (DNS/TLS/timeout)
  3. Configure proxy/HTTPS_PROXY and CA bundle correctly in restricted networks
  4. Retry after transient outages; add timeout/retry around the command

Example fix

// before
const resp = await fetch(url); // may reject
// after
try { const resp = await fetch(url); } catch (e) { console.error('network issue:', e.message); process.exit(1); }
Defensive patterns

Strategy: retry

Validate before calling

const reachable = await fetch('https://huggingface.co', { method: 'HEAD' }).then(r => r.ok).catch(() => false);
if (!reachable) throw new Error('huggingface.co unreachable; check network/proxy');

Try / catch

try { await hfDatasets(args); } catch (e) { if (String(e.message).includes('request failed:')) { await sleep(2000); return retry(hfDatasets, args, 3); } throw e; }

Prevention

When it happens

Trigger: fetch rejects: DNS resolution failure, connection refused/timeout, TLS error, offline machine, or request cancellation while fetching the datasets API.

Common situations: No internet or firewall blocking huggingface.co; corporate proxy without CA certs causing TLS errors; DNS misconfiguration; HF briefly unreachable.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/04eedbe49b72f70f. Report an issue: GitHub.