{"record":{"id":"3d64bf4592353449","repo":"jackwener/OpenCLI","slug":"hf-spaces-sort-must-be-one-of-sort-options-join","errorCode":null,"errorMessage":"hf spaces sort must be one of ${SORT_OPTIONS.join(', ')}","messagePattern":"hf spaces sort must be one of (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/hf/spaces.js","lineNumber":32,"sourceCode":"    site: 'hf',\n    name: 'spaces',\n    access: 'read',\n    description: 'Top Hugging Face Spaces (likes / created_at / last_modified).',\n    domain: 'huggingface.co',\n    strategy: Strategy.PUBLIC,\n    browser: false,\n    args: [\n        { name: 'sort', type: 'string', default: 'likes', help: `Sort key: ${SORT_OPTIONS.join(', ')}` },\n        { name: 'search', type: 'string', required: false, help: 'Optional name/owner substring filter (e.g. \"stability\", \"openai/\")' },\n        { name: 'sdk', type: 'string', required: false, help: 'Filter by Space SDK: gradio / streamlit / docker / static' },\n        { name: 'limit', type: 'int', default: 20, help: 'Max spaces (max 100; one API page).' },\n    ],\n    columns: ['rank', 'id', 'author', 'sdk', 'likes', 'tags', 'lastModified', 'url'],\n    func: async (args) => {\n        const sortRaw = String(args.sort ?? 'likes').toLowerCase();\n        const sort = SORT_ALIAS[sortRaw] ?? sortRaw;\n        if (!SORT_OPTIONS.includes(sort)) {\n            throw new ArgumentError(`hf spaces 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 spaces limit must be a positive integer');\n        }\n        if (limit > 100) {\n            throw new ArgumentError('hf spaces limit must be <= 100');\n        }\n        const sdk = args.sdk == null ? '' : String(args.sdk).trim().toLowerCase();\n        const allowedSdks = new Set(['', 'gradio', 'streamlit', 'docker', 'static']);\n        if (!allowedSdks.has(sdk)) {\n            throw new ArgumentError(`hf spaces sdk must be one of gradio / streamlit / docker / static`);\n        }\n\n        const url = new URL('https://huggingface.co/api/spaces');\n        url.searchParams.set('sort', sort);\n        url.searchParams.set('direction', '-1');\n        url.searchParams.set('limit', String(limit));","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hf/spaces.js#L14-L50","documentation":"`hf spaces` only accepts three sort keys — 'likes', 'created_at', 'last_modified' (with aliases 'lastmodified'/'createdat') — because the Spaces API rejects other sort values such as 'trending'. If the resolved sort value after alias normalization is not in SORT_OPTIONS, an ArgumentError is thrown before any network request is made.","triggerScenarios":"Running `hf spaces --sort trending` or any sort value outside likes/created_at/last_modified (e.g. 'downloads', 'modified', 'Likes' is fine due to lowercasing, but 'trending' is not).","commonSituations":"Copying sort values from `hf models` or `hf datasets` (which accept more keys like 'downloads' or 'trending') into `hf spaces`; assuming GitHub-style sort names; guessing sort keys without reading --help.","solutions":["Use one of: likes, created_at, last_modified (e.g. `hf spaces --sort last_modified`).","Use the aliases `lastmodified` or `createdat` if you prefer camel-free input.","Run `hf spaces --help` to see the supported sort keys.","Catch ArgumentError and map/normalize your sort value before invoking the command."],"exampleFix":"// before\nhf spaces --sort trending\n// after\nhf spaces --sort likes   // trending is not supported by the Spaces API","handlingStrategy":"validation","validationCode":"const SORT_OPTIONS = ['likes', 'created_at', 'last_modified'];\nconst SORT_ALIAS = { lastmodified: 'last_modified', createdat: 'created_at' };\nconst sort = SORT_ALIAS[String(raw).toLowerCase()] ?? String(raw).toLowerCase();\nif (!SORT_OPTIONS.includes(sort)) throw new Error(`sort must be one of ${SORT_OPTIONS.join(', ')}`);","typeGuard":"function isValidSort(v) {\n  return ['likes', 'created_at', 'last_modified'].includes(String(v ?? 'likes').toLowerCase());\n}","tryCatchPattern":"try {\n  await run(['hf', 'spaces', '--sort', sort]);\n} catch (err) {\n  if (err instanceof ArgumentError && /sort must be one of/.test(err.message)) {\n    console.warn(`Invalid sort \"${sort}\"; defaulting to likes`);\n    await run(['hf', 'spaces', '--sort', 'likes']);\n  } else throw err;\n}","preventionTips":["Only use likes / created_at / last_modified for hf spaces — 'trending' is rejected by the Spaces API itself","Do not copy sort keys from hf models / hf datasets; the allowed sets differ","Run hf spaces --help to confirm the accepted sort keys","Normalize case and hyphens/underscores (lastmodified -> last_modified) before passing sort"],"tags":["huggingface","argument-validation","cli","invalid-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}