{"record":{"id":"7ae32c0acb107a7c","repo":"jackwener/OpenCLI","slug":"hf-datasets-sort-must-be-one-of-sort-options-joi","errorCode":null,"errorMessage":"hf datasets sort must be one of ${SORT_OPTIONS.join(', ')}","messagePattern":"hf datasets sort must be one of (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/hf/datasets.js","lineNumber":30,"sourceCode":"cli({\n    site: 'hf',\n    name: 'datasets',\n    access: 'read',\n    description: 'Top Hugging Face datasets (downloads / likes / trending / freshness).',\n    domain: 'huggingface.co',\n    strategy: Strategy.PUBLIC,\n    browser: false,\n    args: [\n        { name: 'sort', type: 'string', default: 'downloads', help: `Sort key: ${SORT_OPTIONS.join(', ')}` },\n        { name: 'search', type: 'string', required: false, help: 'Optional name/owner substring filter.' },\n        { name: 'limit', type: 'int', default: 20, help: 'Max datasets (max 100; one API page).' },\n    ],\n    columns: ['rank', 'id', 'author', 'downloads', 'likes', 'tags', 'lastModified', 'url'],\n    func: async (args) => {\n        const sortRaw = String(args.sort ?? 'downloads').toLowerCase();\n        const sort = SORT_ALIAS[sortRaw] ?? sortRaw;\n        if (!SORT_OPTIONS.includes(sort)) {\n            throw new ArgumentError(`hf datasets sort must be one of ${SORT_OPTIONS.join(', ')}`);\n        }\n        const limit = Number(args.limit ?? 20);\n        if (!Number.isInteger(limit) || limit <= 0) {\n            throw new ArgumentError('hf datasets limit must be a positive integer');\n        }\n        if (limit > 100) {\n            throw new ArgumentError('hf datasets limit must be <= 100');\n        }\n\n        const url = new URL('https://huggingface.co/api/datasets');\n        url.searchParams.set('sort', sort);\n        url.searchParams.set('direction', '-1');\n        url.searchParams.set('limit', String(limit));\n        url.searchParams.set('full', 'true');\n        if (args.search) url.searchParams.set('search', String(args.search));\n\n        let resp;\n        try {","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hf/datasets.js#L12-L48","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use one of the listed SORT_OPTIONS from the error message (e.g. downloads, likes, lastModified)","Check SORT_ALIAS in clis/hf/datasets.js for accepted shorthand aliases","Fix typos in the sort argument","Normalize input with .toLowerCase() before passing it"],"exampleFix":"// before\nhf datasets --sort stars\n// after\nhf datasets --sort likes  # or another value from SORT_OPTIONS","handlingStrategy":"validation","validationCode":"const SORT_OPTIONS = ['downloads','likes','lastModified']; // per CLI\nconst sort = String(rawSort ?? 'downloads').toLowerCase();\nif (!SORT_OPTIONS.includes(sort)) throw new Error(`invalid sort: ${sort}; use one of ${SORT_OPTIONS.join(', ')}`);","typeGuard":"function isValidSort(v) { return typeof v === 'string' && ['downloads','likes','lastModified'].includes(v.toLowerCase()); }","tryCatchPattern":"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; }","preventionTips":["Validate sort values against SORT_OPTIONS before invoking","Normalize case and check SORT_ALIAS for shorthand","Avoid copying sort keys from other APIs","Add shell completion/whitelist for --sort"],"tags":["validation","arguments","cli","huggingface"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}