jackwener/OpenCLI · error · ArgumentError
--limit must be an integer between 1 and 200
Error message
--limit must be an integer between 1 and 200
What it means
normalizeLimit in utils.js throws an ArgumentError when the --limit value is not an integer in the inclusive range 1-200. The limit caps how many activity items are returned; values outside the band (including NaN from non-numeric input) are rejected.
Source
Thrown at clis/trae-cn/utils.js:40
'Set-Content',
'Out-File',
'mkfs',
'git force/delete/hard/filter/rebase operations',
'destructive database commands',
];
export function normalizeTimeout(value, fallback = 60) {
const timeout = value === undefined || value === null ? fallback : Number(value);
if (!Number.isInteger(timeout) || timeout < 1) {
throw new ArgumentError('--timeout must be a positive integer (seconds)');
}
return timeout;
}
export function normalizeLimit(value, fallback = 20) {
const limit = value === undefined || value === null ? fallback : Number(value);
if (!Number.isInteger(limit) || limit < 1 || limit > 200) {
throw new ArgumentError('--limit must be an integer between 1 and 200');
}
return limit;
}
export function normalizeMaxChars(value, fallback = 6000) {
const maxChars = value === undefined || value === null ? fallback : Number(value);
if (!Number.isInteger(maxChars) || maxChars < 0 || maxChars > 1_000_000) {
throw new ArgumentError('--max-chars must be an integer between 0 and 1000000');
}
return maxChars;
}
export function normalizeDuration(value, fallback = 30) {
const duration = value === undefined || value === null ? fallback : Number(value);
if (!Number.isInteger(duration) || duration < 1 || duration > 3600) {
throw new ArgumentError('--duration must be an integer between 1 and 3600 seconds');
}
return duration;View on GitHub (pinned to 49907e53dc)
Solutions
- Pass an integer between 1 and 200, e.g. --limit 50.
- Omit --limit to use the default of 20.
- Clamp large values to 200 in your script before passing.
- Guard against empty variables: --limit "${LIMIT:-20}".
Example fix
// before opencli trae-cn activity --limit 500 // after opencli trae-cn activity --limit 200
Defensive patterns
Strategy: validation
Validate before calling
function assertLimit(v, fallback = 20) {
const n = v === undefined || v === null ? fallback : Number(v);
if (!Number.isInteger(n) || n < 1 || n > 200) throw new Error(`Invalid --limit: ${JSON.stringify(v)}; must be an integer 1-200`);
return n;
} Type guard
function isValidLimit(v) {
return v === undefined || v === null ||
(Number.isInteger(Number(v)) && Number(v) >= 1 && Number(v) <= 200);
} Try / catch
try {
return await listActivities(limit);
} catch (e) {
if (e instanceof ArgumentError && e.message.includes('--limit')) {
return listActivities(Math.min(Math.max(Number(limit) || 20, 1), 200));
}
throw e;
} Prevention
- Clamp requested limits to [1, 200] before passing.
- Never use 0 or huge values to mean 'all' — use the max 200.
- Default to omitting --limit when the default 20 suffices.
- Guard empty shell variables with ${LIMIT:-20}.
When it happens
Trigger: Running a command with `--limit 0`, `--limit 201`, `--limit -1`, `--limit 10.5`, or non-numeric strings like `--limit all`.
Common situations: Trying to fetch 'everything' with --limit 0 or a huge number like 99999; unit tests hardcoding boundary values; scripts passing empty variables (Number('') === 0).
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 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/464ecec3b81f63a3.
Report an issue: GitHub.