{"record":{"id":"eeeb5ee723134b69","repo":"jackwener/OpenCLI","slug":"hf-spaces-limit-must-be-a-positive-integer","errorCode":null,"errorMessage":"hf spaces limit must be a positive integer","messagePattern":"hf spaces limit must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/hf/spaces.js","lineNumber":36,"sourceCode":"    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));\n        url.searchParams.set('full', 'true');\n        if (args.search) url.searchParams.set('search', String(args.search));\n        if (sdk) url.searchParams.set('sdk', sdk);\n","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hf/spaces.js#L18-L54","documentation":"`hf spaces` validates that the `limit` argument, after `Number()` coercion, is an integer greater than 0. Values like 0, negative numbers, NaN (from non-numeric strings), or fractional numbers throw this ArgumentError before any request is made.","triggerScenarios":"Running `hf spaces --limit 0`, `--limit -5`, `--limit abc` (NaN), or `--limit 10.5` (non-integer after Number coercion).","commonSituations":"Scripting the CLI with a variable that is empty or unset (coerces to 0 or NaN); typo like `--limit 2O` (letter O); passing a float from a computed value; copying `limit=0` defaults from other tools.","solutions":["Pass a positive integer, e.g. `hf spaces --limit 50`.","Check the value in your wrapper script before invoking: it must satisfy Number.isInteger(n) && n > 0.","Remember the hard cap is 100 (one API page) — use values 1–100.","Catch ArgumentError and fall back to the default limit of 20 when input is invalid."],"exampleFix":"// before\nconst limit = process.env.LIMIT || 0; // 0 -> error\nhf spaces --limit ${limit}\n// after\nconst limit = Math.max(1, parseInt(process.env.LIMIT, 10) || 20);\nhf spaces --limit ${limit}","handlingStrategy":"validation","validationCode":"const n = Number(rawLimit ?? 20);\nif (!Number.isInteger(n) || n <= 0) throw new Error('limit must be a positive integer');","typeGuard":"function isValidLimit(v) {\n  return Number.isInteger(v) && v > 0;\n}","tryCatchPattern":"try {\n  await run(['hf', 'spaces', '--limit', String(rawLimit)]);\n} catch (err) {\n  if (err instanceof ArgumentError && /limit must be a positive integer/.test(err.message)) {\n    console.warn('Invalid limit; using default 20');\n    await run(['hf', 'spaces']);\n  } else throw err;\n}","preventionTips":["Coerce and validate numeric CLI inputs in wrapper scripts before passing them through","Watch for empty/undefined env vars that coerce to NaN or 0","Use parseInt with a fallback default instead of passing raw strings","Remember the valid range is 1–100 inclusive"],"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"}