jackwener/OpenCLI · error · CommandExecutionError

hf datasets failed: HTTP ${resp.status}

Error message

hf datasets failed: HTTP ${resp.status}

What it means

The Hugging Face datasets API responded, but with a non-2xx status (resp.ok false), so the command throws CommandExecutionError reporting the HTTP status. This indicates the API rejected the request (rate limit, server error, bad parameters accepted only at server side).

Source

Thrown at clis/hf/datasets.js:59

        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) : '';
            const tags = Array.isArray(d.tags) ? d.tags.filter(t => !t.startsWith('license:')).slice(0, 10).join(', ') : '';
            return {
                rank: i + 1,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check resp.status in the message and consult HF API docs for that code
  2. Retry with backoff on 429/5xx
  3. Reduce request frequency or add authentication headers if rate-limited
  4. Verify sort/limit query parameters against the current HF API contract

Example fix

// before
await fetch(url); // assumes success
// after
const resp = await fetch(url); if (resp.status === 429) { await sleep(5000); return retry(); }
Defensive patterns

Strategy: retry

Validate before calling

const pre = await fetch('https://huggingface.co/api/datasets?limit=1'); if (!pre.ok) console.warn(`HF API unhealthy: HTTP ${pre.status}; wait or reduce rate`);

Try / catch

try { await hfDatasets(args); } catch (e) { const m = /HTTP (\d+)/.exec(e.message); if (m && (m[1] === '429' || m[1].startsWith('5'))) { await sleep(5000); return retry(hfDatasets, args, 3); } throw e; }

Prevention

When it happens

Trigger: GET https://huggingface.co/api/datasets?sort=...&limit=... returns 429 (rate limited), 5xx (server error), or another non-OK status.

Common situations: Hammering the API and hitting rate limits; HF incident/5xx outage; blocked request via corporate proxy returning 403; deprecated API parameter causing 400.

Related errors


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