{"record":{"id":"4caccc8a9b056eb8","repo":"jackwener/OpenCLI","slug":"limit-must-be-max-limit-4caccc","errorCode":null,"errorMessage":"limit must be <= ${MAX_LIMIT}","messagePattern":"limit must be <= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/uisdc/news.js","lineNumber":15,"sourceCode":"import { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, CommandExecutionError, EmptyResultError, getErrorMessage } from '@jackwener/opencli/errors';\n\nconst UISDC_NEWS_URL = 'https://www.uisdc.com/news';\nconst DEFAULT_LIMIT = 20;\nconst MAX_LIMIT = 50;\n\nfunction normalizeLimit(value) {\n    const raw = value ?? DEFAULT_LIMIT;\n    const limit = Number(raw);\n    if (!Number.isInteger(limit) || limit <= 0) {\n        throw new ArgumentError('limit must be a positive integer', `Example: opencli uisdc news --limit ${DEFAULT_LIMIT}`);\n    }\n    if (limit > MAX_LIMIT) {\n        throw new ArgumentError(`limit must be <= ${MAX_LIMIT}`, `Example: opencli uisdc news --limit ${MAX_LIMIT}`);\n    }\n    return limit;\n}\n\nfunction normalizeText(value) {\n    return String(value ?? '').replace(/\\s+/g, ' ').trim();\n}\n\nfunction buildExtractUisdcNewsJs() {\n    return `\n      (() => {\n        const cards = Array.from(document.querySelectorAll(\n          '.news-list > .news-item:first-child > .item-content > .dubao-items > .dubao-item'\n        ));\n        if (cards.length === 0) {\n          return {\n            ok: false,\n            reason: 'selector-missing',","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/uisdc/news.js#L1-L33","documentation":"normalizeLimit validates the --limit flag for the `uisdc news` command. When the requested limit exceeds MAX_LIMIT, it throws an ArgumentError explaining the ceiling, because fetching unbounded rows would be wasteful and unstable. The error message includes a ready-to-copy example using the maximum allowed value.","triggerScenarios":"Running `opencli uisdc news --limit` with a number greater than MAX_LIMIT (e.g. --limit 100 when MAX_LIMIT is lower). normalizeLimit is called from the limit handler before any page load.","commonSituations":"Users assuming the CLI caps silently instead of erroring; scripts parameterized with a large default limit; copying --limit values from other commands with higher ceilings.","solutions":["Lower the --limit value to MAX_LIMIT or below","Run `opencli uisdc news --limit <MAX_LIMIT>` as shown in the error's example hint","Check the constant MAX_LIMIT at the top of clis/uisdc/news.js for the exact ceiling"],"exampleFix":"// before\nopencli uisdc news --limit 500\n// after\nopencli uisdc news --limit 20  # assume MAX_LIMIT = 20","handlingStrategy":"validation","validationCode":"function safeLimit(v, max) { const n = Number(v); return Number.isInteger(n) && n > 0 && n <= max ? n : null; }\nconst limit = safeLimit(myLimit, 20); if (limit === null) limit = DEFAULT_LIMIT;","typeGuard":"function isValidLimit(v, max) { const n = Number(v); return Number.isInteger(n) && n > 0 && n <= max; }","tryCatchPattern":"try { const rows = await run(); } catch (e) { if (e.name === 'ArgumentError') { console.error(e.message, e.hint); process.exitCode = 2; } else throw e; }","preventionTips":["Clamp user input with Math.min(Math.max(1, n), MAX_LIMIT) instead of passing raw values","Read the constant MAX_LIMIT from the CLI source before scripting large batch runs","Use the error's example hint, which already shows a valid limit"],"tags":["cli","validation","argument-error","limit"],"backgroundTag":"invalid-cli-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}