{"record":{"id":"6aef60c8fb791559","repo":"jackwener/OpenCLI","slug":"mdn-limit-must-be-maxvalue","errorCode":null,"errorMessage":"mdn limit must be <= ${maxValue}","messagePattern":"mdn limit must be <= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/mdn/search.js","lineNumber":26,"sourceCode":"\nconst MDN_BASE = 'https://developer.mozilla.org';\nconst UA = 'opencli-mdn-adapter (+https://github.com/jackwener/opencli)';\nconst ALLOWED_LOCALES = new Set(['en-US', 'de', 'es', 'fr', 'ja', 'ko', 'pt-BR', 'ru', 'zh-CN', 'zh-TW']);\n\nfunction requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`mdn ${label} cannot be empty`);\n    return s;\n}\n\nfunction requireBoundedInt(value, defaultValue, maxValue) {\n    const raw = value ?? defaultValue;\n    const n = typeof raw === 'number' ? raw : Number(raw);\n    if (!Number.isInteger(n) || n <= 0) {\n        throw new ArgumentError('mdn limit must be a positive integer');\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`mdn limit must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nfunction requireLocale(value) {\n    const s = String(value ?? 'en-US').trim();\n    if (!ALLOWED_LOCALES.has(s)) {\n        throw new ArgumentError(\n            `mdn locale \"${value}\" is not supported`,\n            `Allowed locales: ${[...ALLOWED_LOCALES].join(' / ')}`,\n        );\n    }\n    return s;\n}\n\ncli({\n    site: 'mdn',\n    name: 'search',","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/mdn/search.js#L8-L44","documentation":"requireBoundedInt also enforces an upper bound: if the parsed integer exceeds maxValue, it throws this ArgumentError with the cap interpolated. This prevents oversized requests to the MDN search API.","triggerScenarios":"Passing a limit larger than the adapter's maximum allowed value (e.g. --limit 1000 when maxValue is smaller) to mdn search.","commonSituations":"Users assuming the API accepts unlimited page sizes; scripts passing fetched-count totals as a limit; copying limits from other MDN tooling with different caps.","solutions":["Lower the limit to at most the stated maximum in the error message.","Inspect the adapter's call site to find maxValue (e.g. clis/mdn/search.js where limit is passed) and comply.","Clamp the value in your script: Math.min(limit, maxAllowed).","Paginate with multiple smaller searches instead of one huge limit."],"exampleFix":"// before\nawait mdnSearch({ query: 'array map', limit: 500 });\n// after\nconst MAX = 50;\nawait mdnSearch({ query: 'array map', limit: Math.min(500, MAX) });","handlingStrategy":"validation","validationCode":"const n = Number(rawLimit);\nif (Number.isInteger(n) && n > MAX_LIMIT) throw new RangeError(`limit must be <= ${MAX_LIMIT}`);","typeGuard":"function isWithinLimit(v, max) { return Number.isInteger(v) && v > 0 && v <= max; }","tryCatchPattern":"try { await mdnSearch({ query, limit }); } catch (e) { const m = /limit must be <= (\\d+)/.exec(e.message); if (m) { limit = +m[1]; return retry(); } throw e; }","preventionTips":["Clamp limits with Math.min(limit, max)","Read the max from the error message and adapt dynamically","Paginate instead of requesting huge page sizes"],"tags":["validation","argument-error","cli"],"backgroundTag":"parameter-out-of-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}