jackwener/OpenCLI · error · ArgumentError
--limit must be an integer between 1 and 100, got ${JSON.str
Error message
--limit must be an integer between 1 and 100, got ${JSON.stringify(raw)} What it means
parseLimit converts the raw --limit CLI argument to a number and requires it to be a finite integer. If the raw value is missing, non-numeric, or a float (e.g. "abc", "", 2.5), an ArgumentError is thrown with the JSON-encoded offending value so the caller can see exactly what was passed.
Source
Thrown at clis/smzdm/search.js:41
return rows;
}
function parseLimit(raw) {
let parsed;
if (raw == null) {
parsed = 20;
}
else if (typeof raw === 'number') {
parsed = raw;
}
else if (typeof raw === 'string' && /^[0-9]+$/.test(raw)) {
parsed = Number(raw);
}
else {
parsed = NaN;
}
if (!Number.isFinite(parsed) || !Number.isInteger(parsed)) {
throw new ArgumentError(`--limit must be an integer between 1 and 100, got ${JSON.stringify(raw)}`);
}
if (parsed < 1 || parsed > 100) {
throw new ArgumentError(`--limit must be between 1 and 100, got ${parsed}`);
}
return parsed;
}
/**
* Build the in-page extraction script. Every result row carries the full
* declared column set; interaction metrics default to 0 and the update time
* to '' when a list item omits them, so no column is ever silently dropped.
*/
function buildSmzdmSearchJs(limit) {
return `
(() => {
const limit = ${limit};
const items = document.querySelectorAll('li.feed-row-wide');
const results = [];View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a whole number between 1 and 100: --limit 20.
- Check for empty or unset values in shell scripts calling the CLI (use ${VAR:-20} defaults).
- Validate/round the value in wrapper scripts before invoking the CLI.
Example fix
// before opencli smzdm search headphones --limit 2.5 // after opencli smzdm search headphones --limit 25
Defensive patterns
Strategy: validation
Validate before calling
const n = Number(raw);
if (!Number.isFinite(n) || !Number.isInteger(n) || n < 1 || n > 100) throw new Error(`limit must be an integer 1-100, got ${JSON.stringify(raw)}`); Try / catch
try {
await run(['smzdm', 'search', q, '--limit', String(limit)]);
} catch (e) {
if (e.message.includes('--limit must be an integer')) { console.error(`Fix --limit value: ${e.message}`); }
else throw e;
} Prevention
- Default to a known-good value like --limit 20 in scripts.
- Use ${VAR:-20} shell defaults so unset vars never reach the flag.
- Round/parseInt user input before passing it as --limit.
When it happens
Trigger: Calling the smzdm search command with --limit set to a non-integer or non-numeric value: --limit abc, --limit "", --limit 2.5, or --limit with no value yielding undefined/null.
Common situations: Typo in the flag value; shell quoting issues passing an empty string; scripts interpolating an unbound variable into --limit; users assuming a float or 'all' is accepted.
Understand the failure class
Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.
Related errors
- ${label} must be a non-negative integer, got ${JSON.stringif
- limit must be a positive integer
- bilibili comment ${label} must be a positive integer
- bilibili comment message cannot be empty
- bilibili unfollow target cannot be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/ce7f9fe64459e540.
Report an issue: GitHub.