{"record":{"id":"4fa2c0a12c531bef","repo":"jackwener/OpenCLI","slug":"rest-countries-label-must-be-maxvalue","errorCode":null,"errorMessage":"rest-countries ${label} must be <= ${maxValue}","messagePattern":"rest-countries (.+?) must be <= (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/rest-countries/utils.js","lineNumber":35,"sourceCode":"    'name', 'cca2', 'cca3', 'ccn3', 'capital', 'region', 'subregion',\n    'population', 'area', 'languages', 'currencies', 'flag', 'latlng', 'timezones',\n    'independent', 'unMember', 'landlocked',\n].join(',');\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`rest-countries ${label} cannot be empty`);\n    return s;\n}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\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(`rest-countries ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`rest-countries ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport function requireRegion(value) {\n    const raw = String(value ?? '').trim().toLowerCase();\n    if (!raw) throw new ArgumentError('rest-countries region is required (e.g. \"europe\", \"asia\")');\n    if (!REST_COUNTRIES_REGIONS.has(raw)) {\n        throw new ArgumentError(\n            `rest-countries region \"${value}\" is not recognised`,\n            `Allowed regions: ${[...REST_COUNTRIES_REGIONS].join(', ')}.`,\n        );\n    }\n    return raw;\n}\n\nexport async function restCountriesFetch(url, label) {\n    let resp;","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rest-countries/utils.js#L17-L53","documentation":"requireBoundedInt throws ArgumentError when the parsed integer exceeds the command's allowed maximum for the labeled option. Each command sets its own cap (e.g. country allows up to 250, region is capped at exactly 250). The error names both the label and the maxValue so the caller knows the exact ceiling.","triggerScenarios":"Calling the rest-countries country command with limit > 25 (e.g. 100), or region with limit > 250, tripping `if (n > maxValue)` at clis/rest-countries/utils.js:35.","commonSituations":"Assuming the API allows unlimited results; copying a limit from another command with a higher cap; tuning scripts requesting very large pages.","solutions":["Lower limit to the command's max (25 for country, 250 for region).","Read the command docs/CLI help for the supported limit range.","Paginate manually if you need more results than the cap.","Clamp the value with Math.min before calling."],"exampleFix":"// before\nawait countryCommand({ name: 'a', limit: 1000 });\n// after\nawait countryCommand({ name: 'a', limit: Math.min(userLimit, 250) });","handlingStrategy":"validation","validationCode":"const MAX = { country: 25, region: 250 };\nif (limit > MAX[command]) {\n  limit = MAX[command]; // clamp instead of failing\n}","typeGuard":"function isWithinLimit(n, max) { return Number.isInteger(n) && n > 0 && n <= max; }","tryCatchPattern":"try {\n  await countryCommand({ name, limit });\n} catch (err) {\n  if (err instanceof ArgumentError && /must be <=/.test(err.message)) {\n    const max = Number(err.message.match(/<= (\\d+)/)?.[1] ?? 25);\n    return countryCommand({ name, limit: max });\n  }\n  throw err;\n}","preventionTips":["Read each command's documented limit cap before setting values.","Clamp user-supplied limits with Math.min against the known max.","Do not assume limits are uniform across commands in a CLI suite.","Paginate instead of inflating a single request beyond the cap."],"tags":["argument-error","validation","bounds","cli"],"backgroundTag":"argument-out-of-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}