jackwener/OpenCLI · error · ArgumentError
--max-chars must be an integer between 0 and 1000000
Error message
--max-chars must be an integer between 0 and 1000000
What it means
normalizeMaxChars in utils.js throws an ArgumentError when the --max-chars value is not an integer in the range 0-1000000. This option truncates captured activity text; 0 is allowed (captures nothing) but negatives, floats, and non-numbers are rejected.
Source
Thrown at clis/trae-cn/utils.js:48
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;
}
export function normalizeInterval(value, fallback = 2) {
const interval = value === undefined || value === null ? fallback : Number(value);
if (!Number.isInteger(interval) || interval < 1 || interval > 300) {
throw new ArgumentError('--interval must be an integer between 1 and 300 seconds');
}
return interval;View on GitHub (pinned to 49907e53dc)
Solutions
- Pass an integer between 0 and 1000000, e.g. --max-chars 6000.
- Omit --max-chars to use the 6000 default.
- Use --max-chars 1000000 (the maximum) rather than a larger value.
- Fix scripts so unset variables don't produce invalid numbers.
Example fix
// before opencli trae-cn activity --max-chars 99999999 // after opencli trae-cn activity --max-chars 1000000
Defensive patterns
Strategy: validation
Validate before calling
function assertMaxChars(v, fallback = 6000) {
const n = v === undefined || v === null ? fallback : Number(v);
if (!Number.isInteger(n) || n < 0 || n > 1_000_000) throw new Error(`Invalid --max-chars: ${JSON.stringify(v)}; must be an integer 0-1000000`);
return n;
} Type guard
function isValidMaxChars(v) {
return v === undefined || v === null ||
(Number.isInteger(Number(v)) && Number(v) >= 0 && Number(v) <= 1_000_000);
} Try / catch
try {
return await listActivities(maxChars);
} catch (e) {
if (e instanceof ArgumentError && e.message.includes('--max-chars')) {
return listActivities(Math.min(Math.max(Number(maxChars) || 6000, 0), 1_000_000));
}
throw e;
} Prevention
- Cap values at 1000000 instead of inventing larger 'unlimited' numbers.
- Remember 0 is valid (truncate everything) but negatives are not.
- Avoid unit suffixes like 10k — pass the expanded integer.
- Omit the flag to accept the 6000 default.
When it happens
Trigger: Running a command with `--max-chars -1`, `--max-chars 1000001`, `--max-chars 5.5`, or non-numeric strings like `--max-chars unlimited`.
Common situations: Trying to remove the cap by passing a huge number beyond 1,000,000; empty shell variables (Number('') === 0 is valid here, but ' ' trims to '' -> 0); unit-suffixed values like `--max-chars 10k`.
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/0b705acb514753fb.
Report an issue: GitHub.