{"record":{"id":"442ba7d5d75e1bfa","repo":"jackwener/OpenCLI","slug":"hf-models-sort-must-be-one-of-sort-options-join","errorCode":null,"errorMessage":"hf models sort must be one of ${SORT_OPTIONS.join(', ')}","messagePattern":"hf models sort must be one of (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/hf/models.js","lineNumber":31,"sourceCode":"    site: 'hf',\n    name: 'models',\n    access: 'read',\n    description: 'Top Hugging Face models (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 (e.g. \"llama\", \"mistralai/\")' },\n        { name: 'pipeline', type: 'string', required: false, help: 'Filter by pipeline tag (e.g. text-generation, image-classification)' },\n        { name: 'limit', type: 'int', default: 20, help: 'Max models (max 100; one API page).' },\n    ],\n    columns: ['rank', 'id', 'author', 'pipelineTag', '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 models 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 models limit must be a positive integer');\n        }\n        if (limit > 100) {\n            throw new ArgumentError('hf models limit must be <= 100');\n        }\n\n        const url = new URL('https://huggingface.co/api/models');\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        if (args.pipeline) url.searchParams.set('pipeline_tag', String(args.pipeline));\n\n        let resp;","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hf/models.js#L13-L49","documentation":"ArgumentError thrown at clis/hf/models.js:31 when the --sort argument, after lowercasing and alias mapping (lastmodified→last_modified, createdat→created_at), is not one of SORT_OPTIONS: downloads, likes, trending, created_at, last_modified. The library validates the sort key client-side before building the https://huggingface.co/api/models request to avoid sending an invalid query to the API.","triggerScenarios":"Passing `hf models --sort <value>` where value is not in SORT_OPTIONS after normalization — e.g. --sort trending-score, --sort downloads7d, --sort last-modified (hyphenated, not in alias map), or any arbitrary string.","commonSituations":"Guessing sort keys from Hugging Face web UI names (e.g. 'trendingScore', 'mostDownloads') instead of the CLI's exact keys; using hyphenated variants like 'last-modified' or camelCase 'createdAt' that neither the alias map nor the option list accepts; scripting the CLI with a sort value read from config written for another tool.","solutions":["Use one of the exact accepted values: downloads, likes, trending, created_at, last_modified.","Use the alias forms 'lastmodified' or 'createdat' (case-insensitive) if more natural.","Check `opencli hf models --help`, which lists the valid sort keys in the --sort help text.","If a desired sort key is missing, it must be added to SORT_OPTIONS in clis/hf/models.js (and mapped in SORT_ALIAS if spelled differently)."],"exampleFix":"// before\nopencli hf models --sort last-modified\n// after\nopencli hf models --sort last_modified","handlingStrategy":"validation","validationCode":"const SORT_OPTIONS = ['downloads', 'likes', 'trending', 'created_at', 'last_modified'];\nconst SORT_ALIAS = { lastmodified: 'last_modified', createdat: 'created_at' };\nfunction validateSort(raw) {\n  const s = String(raw ?? 'downloads').toLowerCase();\n  const norm = SORT_ALIAS[s] ?? s;\n  if (!SORT_OPTIONS.includes(norm)) throw new Error(`sort must be one of ${SORT_OPTIONS.join(', ')}`);\n  return norm;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await run(`hf models --sort ${sort}`);\n} catch (e) {\n  if (String(e.message).includes('sort must be one of')) {\n    console.error(`Invalid --sort \"${sort}\"; valid: downloads, likes, trending, created_at, last_modified`);\n  } else throw e;\n}","preventionTips":["Copy sort keys from `opencli hf models --help` rather than the HF web UI.","Use underscores: created_at / last_modified, not hyphens or camelCase.","Keep sort values in a shared constant in wrapper scripts.","Normalize case (the CLI lowercases, but avoid relying on it)."],"tags":["argument-validation","cli","huggingface"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}