{"record":{"id":"3f5282416849ad5e","repo":"jackwener/OpenCLI","slug":"rest-countries-region-is-required-e-g-europe","errorCode":null,"errorMessage":"rest-countries region is required (e.g. \"europe\", \"asia\")","messagePattern":"rest-countries region is required \\(e\\.g\\. \"europe\", \"asia\"\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/rest-countries/utils.js","lineNumber":42,"sourceCode":"    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;\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.',","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rest-countries/utils.js#L24-L60","documentation":"requireRegion throws ArgumentError when the region argument is empty after trimming. Because region is the core path segment of the /v3.1/region/{region} URL, an empty value would produce a broken request, so it fails fast with a message showing example regions. Only later does it check membership in REST_COUNTRIES_REGIONS.","triggerScenarios":"Calling the rest-countries region command with no `region` argument, or region = '' / whitespace / null, hitting the `if (!raw)` check at clis/rest-countries/utils.js:42.","commonSituations":"Missing CLI flag; an unset environment variable interpolated into the command; interactive scripts where the user skipped the prompt.","solutions":["Provide a region value such as 'europe' or 'asia'.","Validate the input is non-empty before invoking the command.","Fix the calling script/config so the region variable is populated.","Catch ArgumentError and show the accepted region list."],"exampleFix":"// before\nawait regionCommand({ region: '' });\n// after\nawait regionCommand({ region: 'asia' });","handlingStrategy":"validation","validationCode":"if (typeof region !== 'string' || !region.trim()) {\n  throw new TypeError('region is required (e.g. \"europe\", \"asia\")');\n}","typeGuard":"function isNonEmptyRegion(v) { return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try {\n  await regionCommand({ region });\n} catch (err) {\n  if (err instanceof ArgumentError && /region is required/.test(err.message)) {\n    printUsage('region is required: africa|americas|asia|europe|oceania');\n  } else {\n    throw err;\n  }\n}","preventionTips":["Make region a required, prompted field in interactive flows.","Check env/config variables are set before constructing the command call.","Fail fast with usage help when the region argument is absent.","Add a smoke test that runs each command with valid minimal args."],"tags":["argument-error","validation","cli","rest-countries"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}