jackwener/OpenCLI · error · ArgumentError
--page must be a positive decimal integer, got: ${String(val
Error message
--page must be a positive decimal integer, got: ${String(value)} What it means
The string branch of parsePageArg: any string that is not null/empty and does not fully match /^[1-9]\d*$/ (a positive decimal integer without leading zeros, signs, or whitespace) throws this ArgumentError with the stringified value. This rejects '0', '-1', '1.5', '01', '1e3', ' 2', and non-strings like objects.
Source
Thrown at clis/bilibili/utils.js:91
reject(new Error(`Cannot resolve BV ID from short URL: ${trimmed}`));
});
req.on('error', reject);
req.setTimeout(4000, () => { req.destroy(); reject(new Error(`Timeout resolving short URL: ${trimmed}`)); });
});
}
/**
* 解析 --page 选集序号(分P / 视频选集)。
* 缺省/空串 → null(不下钻,保持整集默认 P1 旧行为)。
* 非正十进制整数 → 抛 ArgumentError(参数错误,不静默吞)。
*/
export function parsePageArg(value) {
if (value == null || value === '') return null;
if (typeof value === 'number') {
if (Number.isSafeInteger(value) && value >= 1) return value;
throw new ArgumentError(`--page must be a positive decimal integer, got: ${value}`);
}
if (typeof value !== 'string' || !/^[1-9]\d*$/.test(value)) {
throw new ArgumentError(`--page must be a positive decimal integer, got: ${String(value)}`);
}
const n = Number(value);
if (!Number.isSafeInteger(n)) {
throw new ArgumentError(`--page is too large: ${value}`);
}
return n;
}
function readApiPositiveInteger(value, label) {
if (typeof value === 'number' && Number.isSafeInteger(value) && value >= 1) {
return value;
}
if (typeof value === 'string' && /^[1-9]\d*$/.test(value)) {
const n = Number(value);
if (Number.isSafeInteger(n)) return n;
}
throw new CommandExecutionError(`Bilibili view API returned a malformed ${label}`);
}View on GitHub (pinned to 49907e53dc)
Solutions
- Pass the page as a plain decimal string like '2' (no sign, no leading zeros, no decimals)
- Trim and normalize the value before calling: String(value).trim()
- Convert with parseInt(value, 10) and validate Number.isSafeInteger before passing
- Fix the CLI argument format (use --page 2, not --page=2.0 or -page 2)
Example fix
// before
parsePageArg('01');
// after
parsePageArg('1'); Defensive patterns
Strategy: validation
Validate before calling
function normalizePageStr(v) {
const s = String(v ?? '').trim();
return /^[1-9]\d*$/.test(s) ? s : null;
}
const page = normalizePageStr(cliPage); Type guard
function isDecimalPageString(v) {
return typeof v === 'string' && /^[1-9]\d*$/.test(v);
} Try / catch
try {
const page = parsePageArg(value);
} catch (err) {
if (err instanceof ArgumentError && /--page/.test(err.message)) {
console.error(`--page must look like '2' (got '${value}'); using default`);
const page = null;
} else throw err;
} Prevention
- Trim and normalize CLI values before validation (whitespace/signs break the regex)
- Avoid zero-padded numbers ('01') — pass '1'
- Use --page 2 syntax without units or suffixes
- Convert to a number early and pass numbers when you control the caller
When it happens
Trigger: Calling parsePageArg('0'), parsePageArg('-2'), parsePageArg('1.5'), parsePageArg('01'), parsePageArg('abc'), parsePageArg(' 3'), or passing a non-string non-number (object, boolean, array).
Common situations: CLI/framework delivering --page with an '=' sign or stray whitespace; zero-padding page numbers; scripts building the flag with a float format; users typing 'page 2' or '2nd'.
Related errors
- bilibili unfollow target must be a valid space.bilibili.com/
- --page must be a positive decimal integer, got: ${value}
- --page is too large: ${value}
- archive snapshots url cannot be empty
- archive snapshots limit must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/108314a181a06cbf.
Report an issue: GitHub.