{"record":{"id":"117d4f749ff219cf","repo":"jackwener/OpenCLI","slug":"rest-countries-region-value-is-not-recognised","errorCode":null,"errorMessage":"rest-countries region \"${value}\" is not recognised","messagePattern":"rest-countries region \"(.+?)\" is not recognised","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/rest-countries/utils.js","lineNumber":44,"sourceCode":"}\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;\n    try {\n        resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });\n    }\n    catch (err) {\n        throw new CommandExecutionError(\n            `${label} request failed: ${err?.message ?? err}`,\n            'Check that restcountries.com is reachable from this network.',\n        );\n    }","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rest-countries/utils.js#L26-L62","documentation":"requireRegion throws this ArgumentError when the trimmed, lowercased region value is non-empty but not in the REST_COUNTRIES_REGIONS allow-list. REST Countries only recognizes africa, americas, asia, europe, oceania as regions. The error carries a second hint line listing all allowed regions.","triggerScenarios":"Calling the rest-countries region command with values like 'antarctica', 'emea', 'eu', or 'Europe ' variants not in the set (after lowercasing, whitespace is trimmed but the name must still match) at clis/rest-countries/utils.js:44.","commonSituations":"Using business territory groupings (EMEA, APAC) instead of the API's five regions; expecting 'antarctica' to be a region; capitalization confusion (handled) vs. wrong word entirely (not).","solutions":["Use one of: africa, americas, asia, europe, oceania.","Map your internal territory names to the API's region set before calling.","Use the subregion or translation endpoints for finer-grained grouping.","Catch ArgumentError and read err's hint for the allowed list."],"exampleFix":"// before\nawait regionCommand({ region: 'EMEA' });\n// after\nawait regionCommand({ region: 'europe' }); // or 'asia', 'africa', 'americas', 'oceania'","handlingStrategy":"validation","validationCode":"const ALLOWED = new Set(['africa','americas','asia','europe','oceania']);\nconst normalized = String(region ?? '').trim().toLowerCase();\nif (!ALLOWED.has(normalized)) {\n  throw new TypeError(`region must be one of: ${[...ALLOWED].join(', ')}`);\n}","typeGuard":"function isApiRegion(v) {\n  return ['africa','americas','asia','europe','oceania'].includes(String(v ?? '').trim().toLowerCase());\n}","tryCatchPattern":"try {\n  await regionCommand({ region });\n} catch (err) {\n  if (err instanceof ArgumentError && /not recognised/.test(err.message)) {\n    console.error(err.message, err.hint ?? '');\n  } else {\n    throw err;\n  }\n}","preventionTips":["Keep a shared constant list of the five API regions and validate against it.","Map internal territory groupings (EMEA/APAC) to API regions up front.","Lowercase/trim region input before comparison to avoid false mismatches.","Surface the error's allowed-regions hint to end users."],"tags":["argument-error","validation","enum","rest-countries"],"backgroundTag":"invalid-enum-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}