jackwener/OpenCLI · error · ArgumentError

hf datasets sort must be one of ${SORT_OPTIONS.join(', ')}

Error message

hf datasets sort must be one of ${SORT_OPTIONS.join(', ')}

What it means

The hf datasets command validates its --sort argument against SORT_OPTIONS (after applying SORT_ALIAS normalization). Passing a sort key outside that set throws ArgumentError, listing all valid options.

Source

Thrown at clis/hf/datasets.js:30

cli({
    site: 'hf',
    name: 'datasets',
    access: 'read',
    description: 'Top Hugging Face datasets (downloads / likes / trending / freshness).',
    domain: 'huggingface.co',
    strategy: Strategy.PUBLIC,
    browser: false,
    args: [
        { name: 'sort', type: 'string', default: 'downloads', help: `Sort key: ${SORT_OPTIONS.join(', ')}` },
        { name: 'search', type: 'string', required: false, help: 'Optional name/owner substring filter.' },
        { name: 'limit', type: 'int', default: 20, help: 'Max datasets (max 100; one API page).' },
    ],
    columns: ['rank', 'id', 'author', 'downloads', 'likes', 'tags', 'lastModified', 'url'],
    func: async (args) => {
        const sortRaw = String(args.sort ?? 'downloads').toLowerCase();
        const sort = SORT_ALIAS[sortRaw] ?? sortRaw;
        if (!SORT_OPTIONS.includes(sort)) {
            throw new ArgumentError(`hf datasets sort must be one of ${SORT_OPTIONS.join(', ')}`);
        }
        const limit = Number(args.limit ?? 20);
        if (!Number.isInteger(limit) || limit <= 0) {
            throw new ArgumentError('hf datasets limit must be a positive integer');
        }
        if (limit > 100) {
            throw new ArgumentError('hf datasets limit must be <= 100');
        }

        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 {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use one of the listed SORT_OPTIONS from the error message (e.g. downloads, likes, lastModified)
  2. Check SORT_ALIAS in clis/hf/datasets.js for accepted shorthand aliases
  3. Fix typos in the sort argument
  4. Normalize input with .toLowerCase() before passing it

Example fix

// before
hf datasets --sort stars
// after
hf datasets --sort likes  # or another value from SORT_OPTIONS
Defensive patterns

Strategy: validation

Validate before calling

const SORT_OPTIONS = ['downloads','likes','lastModified']; // per CLI
const sort = String(rawSort ?? 'downloads').toLowerCase();
if (!SORT_OPTIONS.includes(sort)) throw new Error(`invalid sort: ${sort}; use one of ${SORT_OPTIONS.join(', ')}`);

Type guard

function isValidSort(v) { return typeof v === 'string' && ['downloads','likes','lastModified'].includes(v.toLowerCase()); }

Try / catch

try { await hfDatasets({ sort }); } catch (e) { if (e instanceof ArgumentError && e.message.includes('sort must be one of')) { console.error(e.message); process.exit(2); } throw e; }

Prevention

When it happens

Trigger: Calling hf datasets with sort set to a string not in SORT_OPTIONS and not mapped by SORT_ALIAS, e.g. --sort stars or a misspelled value like downlodas.

Common situations: Typo in the sort value; copying a sort key from another API (e.g. GitHub's 'stars'); case/alias mismatch where the alias table lacks the variant; script passing empty string.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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