jackwener/OpenCLI · error · ArgumentError
${label} must be >= ${min}
Error message
${label} must be >= ${min} What it means
ArgumentError from normalizePositiveInteger's `min` option, thrown when a value is a valid positive integer but below the caller's configured minimum. Used e.g. for contentLimit with min: 50 — values like 10 are rejected rather than silently raised, keeping validation explicit.
Source
Thrown at clis/1point3acres/utils.js:35
* Throws ArgumentError on non-positive / non-integer / out-of-range input.
*/
export function normalizeLimit(value, defaultValue, maxValue, label = 'limit') {
const limit = normalizePositiveInteger(value, defaultValue, label);
if (limit > maxValue) {
throw new ArgumentError(`${label} must be <= ${maxValue}`);
}
return limit;
}
/** Validate a positive integer argument without silently flooring/clamping. */
export function normalizePositiveInteger(value, defaultValue, label = 'value', { min = 1 } = {}) {
const raw = value ?? defaultValue;
const limit = Number(raw);
if (!Number.isInteger(limit) || limit <= 0) {
throw new ArgumentError(`${label} must be a positive integer`);
}
if (limit < min) {
throw new ArgumentError(`${label} must be >= ${min}`);
}
return limit;
}
const UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0 Safari/537.36';
/** Fetch a GBK-encoded Discuz page and return decoded UTF-8 HTML. */
export async function fetchHtml(url, { headers = {}, cookie = '' } = {}) {
let res;
try {
res = await fetch(url, {
headers: {
'User-Agent': UA,
'Accept': 'text/html,application/xhtml+xml',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
...(cookie ? { Cookie: cookie } : {}),
...headers,
},View on GitHub (pinned to 49907e53dc)
Solutions
- Raise the value to at least the stated minimum (contentLimit >= 50)
- Read the error message: it names the exact minimum (e.g. 'contentLimit must be >= 50')
- If you need less content, post-truncate the returned strings yourself instead of passing sub-minimum values
- Omit the option to use the command default (contentLimit: 400)
Example fix
// before
thread({ tid: '123', contentLimit: 20 }) // ArgumentError: contentLimit must be >= 50
// after
thread({ tid: '123', contentLimit: 50 })
// or post-truncate yourself:
const t = await thread({ tid: '123' });
const short = t.rows.map(r => ({ ...r, content: r.content.slice(0, 20) })); Defensive patterns
Strategy: validation
Validate before calling
const CONTENT_LIMIT_MIN = 50;
const safeContentLimit = (v) => {
const n = Number(v);
if (!Number.isInteger(n) || n < CONTENT_LIMIT_MIN) throw new Error(`contentLimit must be an integer >= ${CONTENT_LIMIT_MIN}`);
return n;
}; Type guard
const meetsMin = (v, min) => Number.isInteger(v) && v >= min;
Try / catch
try {
await thread({ tid, contentLimit });
} catch (e) {
if (e instanceof ArgumentError && /must be >=/.test(e.message)) {
const min = Number(e.message.match(/>= (\d+)/)?.[1]);
await thread({ tid, contentLimit: Math.max(contentLimit, min) });
} else throw e;
} Prevention
- Check the min documented for each option (contentLimit min is 50)
- For shorter excerpts, post-truncate results yourself instead of passing sub-minimum values
- Omit the option to use the sensible default (400)
- Centralize option validation so mins are enforced once
When it happens
Trigger: Passing contentLimit below 50 (e.g. contentLimit: 20) to the thread command; any command whose validator sets { min } and receives an integer smaller than that floor.
Common situations: Wanting shorter excerpts and guessing a small number without checking the minimum; copying a limit from another tool with a smaller floor; config default tuned for a different command.
Related errors
- ${label} must be <= ${maxValue}
- ${label} must be a positive integer
- number "${numRaw}" is not a positive integer
- status "${status}" not in {${TASK_STATUSES.join('|')}} — pre
- <train-no> must not be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/5a85a7198b0d03ff.
Report an issue: GitHub.