jackwener/OpenCLI · warning · ArgumentError
--max-pages must be an integer between 1 and ${HARD_MAX_PAGI
Error message
--max-pages must be an integer between 1 and ${HARD_MAX_PAGINATION_PAGES} What it means
resolveMaxPages validates the --max-pages flag for twitter archive pagination. It must be an integer from 1 up to HARD_MAX_PAGINATION_PAGES; anything else (non-numeric, zero, negative, float, or over the hard cap) throws ArgumentError. The cap protects against runaway request loops against the Twitter API.
Source
Thrown at clis/twitter/archive.js:83
// Escape LS/PS so JSONL stays one physical line even when tweet text contains them.
const text = rows
.map((row) => JSON.stringify(row).replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029'))
.join('\n') + '\n';
fs.appendFileSync(filePath, text, 'utf8');
}
export function removeResumeFile(filePath) {
removeFile(filePath);
}
export function resolveMaxPages(kwargs, fetchAll) {
const raw = kwargs['max-pages'];
if (raw === undefined || raw === null || raw === '') {
return fetchAll ? HARD_MAX_PAGINATION_PAGES : DEFAULT_MAX_PAGINATION_PAGES;
}
const value = Number(raw);
if (!Number.isInteger(value) || value < 1 || value > HARD_MAX_PAGINATION_PAGES) {
throw new ArgumentError(`--max-pages must be an integer between 1 and ${HARD_MAX_PAGINATION_PAGES}`);
}
return value;
}
View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a whole number between 1 and HARD_MAX_PAGINATION_PAGES (check the constant in clis/twitter/archive.js for the exact cap)
- Omit --max-pages entirely to use the default (HARD_MAX when --all, otherwise DEFAULT_MAX_PAGINATION_PAGES)
- Fix the upstream script generating the value (Number() producing NaN or floats)
- Quote the value so shell splitting doesn't corrupt it
Example fix
// before node cli.js twitter archive --max-pages 5000 // after node cli.js twitter archive --max-pages 50 # within 1..HARD_MAX_PAGINATION_PAGES
Defensive patterns
Strategy: validation
Validate before calling
const MAX = HARD_MAX_PAGINATION_PAGES; // check constant in clis/twitter/archive.js
const v = Number(maxPagesArg);
if (!Number.isInteger(v) || v < 1 || v > MAX) throw new Error(`--max-pages must be an integer 1..${MAX}`); Type guard
function isValidMaxPages(v) { return Number.isInteger(v) && v >= 1 && v <= HARD_MAX_PAGINATION_PAGES; } Try / catch
try {
await archiveCmd({ 'max-pages': raw });
} catch (err) {
if (err instanceof ArgumentError && err.message.includes('--max-pages')) {
console.error('Pass an integer in the allowed range or omit the flag for defaults');
} else throw err;
} Prevention
- Omit --max-pages to accept the default (or hard max with --all)
- Round/validate computed values before passing (avoid NaN and floats)
- Quote the argument in shell scripts
- Check HARD_MAX_PAGINATION_PAGES before setting large values
When it happens
Trigger: Passing --max-pages with a value like 0, -1, 2.5, 'abc', or a number exceeding HARD_MAX_PAGINATION_PAGES; thrown from the maxPages command path.
Common situations: Copy-pasting a float like 1.5, computing the value in a script that yields NaN or a string, or trying an unbounded crawl by setting a huge number above the hard limit.
Related errors
- ${label} must be a positive integer
- ${label} must be <= ${maxValue}
- semanticscholar citations offset must be a non-negative inte
- zhihu collection --${name} must be a non-negative integer
- ${label} is required
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/4155ebc1a8b0db9b.
Report an issue: GitHub.