jackwener/OpenCLI · error · ArgumentError
hf datasets limit must be a positive integer
Error message
hf datasets limit must be a positive integer
What it means
The hf datasets command requires limit to be an integer greater than 0 (default 20). Passing a non-integer, zero, negative, or non-numeric value throws ArgumentError with this message.
Source
Thrown at clis/hf/datasets.js:34
description: 'Top Hugging Face datasets (downloads / likes / trending / freshness).',
domain: 'huggingface.co',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'sort', type: 'string', default: 'downloads', help: `Sort key: ${SORT_OPTIONS.join(', ')}` },
{ name: 'search', type: 'string', required: false, help: 'Optional name/owner substring filter.' },
{ name: 'limit', type: 'int', default: 20, help: 'Max datasets (max 100; one API page).' },
],
columns: ['rank', 'id', 'author', 'downloads', 'likes', 'tags', 'lastModified', 'url'],
func: async (args) => {
const sortRaw = String(args.sort ?? 'downloads').toLowerCase();
const sort = SORT_ALIAS[sortRaw] ?? sortRaw;
if (!SORT_OPTIONS.includes(sort)) {
throw new ArgumentError(`hf datasets sort must be one of ${SORT_OPTIONS.join(', ')}`);
}
const limit = Number(args.limit ?? 20);
if (!Number.isInteger(limit) || limit <= 0) {
throw new ArgumentError('hf datasets limit must be a positive integer');
}
if (limit > 100) {
throw new ArgumentError('hf datasets limit must be <= 100');
}
const url = new URL('https://huggingface.co/api/datasets');
url.searchParams.set('sort', sort);
url.searchParams.set('direction', '-1');
url.searchParams.set('limit', String(limit));
url.searchParams.set('full', 'true');
if (args.search) url.searchParams.set('search', String(args.search));
let resp;
try {
resp = await fetch(url, {
headers: {
'Accept': 'application/json',
'User-Agent': 'opencli/1.0 (+https://github.com/jackwener/opencli)',View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a positive integer, e.g. --limit 20
- Check the config/script for empty or undefined limit variables
- Use an integer, not a float or numeric string with decimals
- Omit --limit to use the default of 20
Example fix
// before hf datasets --limit 0 // after hf datasets --limit 20
Defensive patterns
Strategy: validation
Validate before calling
const limit = Number(rawLimit ?? 20);
if (!Number.isInteger(limit) || limit <= 0) throw new Error('limit must be a positive integer'); Type guard
function isValidLimit(v) { const n = Number(v); return Number.isInteger(n) && n > 0; } Try / catch
try { await hfDatasets({ limit }); } catch (e) { if (e instanceof ArgumentError && e.message.includes('limit must be a positive integer')) { console.error(e.message); process.exit(2); } throw e; } Prevention
- Coerce and validate limit before invoking
- Check config/env for empty or NaN limit values
- Use integers only; avoid floats and 0
- Rely on the default (20) when unsure
When it happens
Trigger: Calling hf datasets with --limit 0, --limit -5, --limit abc, or a float like 2.5 — Number(args.limit) fails Number.isInteger or is <= 0.
Common situations: Config file supplying an empty or NaN limit; shell passing an unset variable resulting in 'undefined' -> NaN; users assuming 0 means unlimited; copy-pasted float values.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- hf datasets sort must be one of ${SORT_OPTIONS.join(', ')}
- ${label} is required
- ${label} must be a positive integer
- ${label} must be <= ${maxValue}
- dblp ${label} must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/660b8c6a09cc3908.
Report an issue: GitHub.