jackwener/OpenCLI · error · EmptyResultError

hf models

Error message

hf models

What it means

EmptyResultError('hf models', 'No matching models on huggingface.co.') thrown at clis/hf/models.js:71 when the /api/models response parses successfully but the resulting array is empty (or the body is not an array). It signals that the request succeeded but no models matched, separating empty results from network/HTTP errors.

Source

Thrown at clis/hf/models.js:71

                    '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) : '';
            const tags = Array.isArray(m.tags) ? m.tags.filter(t => !t.startsWith('license:')).slice(0, 10).join(', ') : '';
            return {
                rank: i + 1,
                id,
                author,
                pipelineTag: m.pipeline_tag || m.pipelineTag || '',
                downloads: m.downloads ?? 0,
                likes: m.likes ?? 0,
                tags,
                lastModified: m.lastModified ? String(m.lastModified).slice(0, 10) : '',
                url: id ? `https://huggingface.co/${id}` : '',
            };
        });

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run with a corrected or broader --search value (verify exact owner/model spelling on huggingface.co).
  2. Remove --pipeline or use a valid pipeline tag (e.g. text-generation, image-classification).
  3. Drop all filters (`opencli hf models`) to confirm the API returns data at all.
  4. If HF returns [] even unfiltered, check https://huggingface.co status for an API incident.

Example fix

// before
opencli hf models --pipeline text-gen
// after
opencli hf models --pipeline text-generation
Defensive patterns

Strategy: fallback

Validate before calling

// Check that a search term actually matches before running the command
const r = await fetch('https://huggingface.co/api/models?search=' + encodeURIComponent(term) + '&limit=1');
const rows = await r.json();
if (!Array.isArray(rows) || rows.length === 0) console.warn(`No models match "${term}"`);

Try / catch

try {
  await run(`hf models --search ${term} --pipeline ${tag}`);
} catch (e) {
  if (e.name === 'EmptyResultError') {
    console.warn('No models matched; falling back to unfiltered listing');
    await run('hf models');
  } else throw e;
}

Prevention

When it happens

Trigger: Running `hf models` with a --search term or --pipeline filter that matches zero models — e.g. --search with a misspelled model name, --search 'orgname/' for a nonexistent owner, or --pipeline with a tag no model uses — while the API itself responds 200 with [].

Common situations: Typo in --search ('mistralai/' vs 'mistalai/'); using a pipeline tag not in HF's vocabulary (e.g. 'text-gen' instead of 'text-generation'); searching for a private/gated repo that the public API does not list; combining filters that nothing satisfies.

Related errors


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