{"record":{"id":"4155ebc1a8b0db9b","repo":"jackwener/OpenCLI","slug":"max-pages-must-be-an-integer-between-1-and-har","errorCode":null,"errorMessage":"--max-pages must be an integer between 1 and ${HARD_MAX_PAGINATION_PAGES}","messagePattern":"--max-pages must be an integer between 1 and (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"warning","filePath":"clis/twitter/archive.js","lineNumber":83,"sourceCode":"    // Escape LS/PS so JSONL stays one physical line even when tweet text contains them.\n    const text = rows\n        .map((row) => JSON.stringify(row).replace(/\\u2028/g, '\\\\u2028').replace(/\\u2029/g, '\\\\u2029'))\n        .join('\\n') + '\\n';\n    fs.appendFileSync(filePath, text, 'utf8');\n}\n\nexport function removeResumeFile(filePath) {\n    removeFile(filePath);\n}\n\nexport function resolveMaxPages(kwargs, fetchAll) {\n    const raw = kwargs['max-pages'];\n    if (raw === undefined || raw === null || raw === '') {\n        return fetchAll ? HARD_MAX_PAGINATION_PAGES : DEFAULT_MAX_PAGINATION_PAGES;\n    }\n    const value = Number(raw);\n    if (!Number.isInteger(value) || value < 1 || value > HARD_MAX_PAGINATION_PAGES) {\n        throw new ArgumentError(`--max-pages must be an integer between 1 and ${HARD_MAX_PAGINATION_PAGES}`);\n    }\n    return value;\n}\n","sourceCodeStart":65,"sourceCodeEnd":87,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/archive.js#L65-L87","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nnode cli.js twitter archive --max-pages 5000\n// after\nnode cli.js twitter archive --max-pages 50   # within 1..HARD_MAX_PAGINATION_PAGES","handlingStrategy":"validation","validationCode":"const MAX = HARD_MAX_PAGINATION_PAGES; // check constant in clis/twitter/archive.js\nconst v = Number(maxPagesArg);\nif (!Number.isInteger(v) || v < 1 || v > MAX) throw new Error(`--max-pages must be an integer 1..${MAX}`);","typeGuard":"function isValidMaxPages(v) { return Number.isInteger(v) && v >= 1 && v <= HARD_MAX_PAGINATION_PAGES; }","tryCatchPattern":"try {\n  await archiveCmd({ 'max-pages': raw });\n} catch (err) {\n  if (err instanceof ArgumentError && err.message.includes('--max-pages')) {\n    console.error('Pass an integer in the allowed range or omit the flag for defaults');\n  } else throw err;\n}","preventionTips":["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"],"tags":["arguments","validation","pagination"],"backgroundTag":"invalid-argument-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}