{"record":{"id":"e21f51538bdc32e6","repo":"jackwener/OpenCLI","slug":"hf-models-limit-must-be-a-positive-integer","errorCode":null,"errorMessage":"hf models limit must be a positive integer","messagePattern":"hf models limit must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/hf/models.js","lineNumber":35,"sourceCode":"    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;\n        try {\n            resp = await fetch(url, {\n                headers: {\n                    'Accept': 'application/json',","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hf/models.js#L17-L53","documentation":"ArgumentError thrown at clis/hf/models.js:35 when the --limit argument, coerced with Number(), is not an integer or is <= 0. The library validates the limit before constructing the /api/models query because the HF API requires a positive integer limit parameter.","triggerScenarios":"Passing `hf models --limit` with a non-integer (e.g. 12.5), zero, a negative number, or a value that Number() turns into NaN (e.g. --limit abc, --limit '', --limit '20x').","commonSituations":"Shell variable interpolating empty (--limit \"$LIMIT\" with LIMIT unset); typo like --limit 2O (letter O) silently producing NaN; scripts computing limit from arithmetic that yields 0 or a float; copy-pasted limits like '1,000' with a thousands separator.","solutions":["Pass a whole number >= 1, e.g. --limit 20.","Omit the flag to use the default of 20.","Strip formatting from scripted values (no commas, no units) and ensure the variable is set before interpolation.","Validate with Number.isInteger(n) && n > 0 in any wrapper script before invoking."],"exampleFix":"// before\nopencli hf models --limit \"$ROWS\"   # ROWS is empty -> NaN\n// after\nROWS=${ROWS:-20}; opencli hf models --limit \"$ROWS\"","handlingStrategy":"validation","validationCode":"function validateLimit(raw) {\n  const n = Number(raw ?? 20);\n  if (!Number.isInteger(n) || n <= 0) throw new Error(`limit must be a positive integer, got ${JSON.stringify(raw)}`);\n  return n;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await run(`hf models --limit ${limit}`);\n} catch (e) {\n  if (String(e.message).includes('limit must be a positive integer')) {\n    console.error(`--limit \"${limit}\" is not a positive integer; using default 20`);\n    await run('hf models');\n  } else throw e;\n}","preventionTips":["Always pass plain integers (20, not 20.0, '1,000', or '20x').","Default unset shell variables: LIMIT=${LIMIT:-20}.","Guard scripted values with Number.isInteger before invoking.","Watch for letter-for-digit typos (2O vs 20)."],"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"}