jackwener/OpenCLI · error · ArgumentError
rest-countries region is required (e.g. "europe", "asia")
Error message
rest-countries region is required (e.g. "europe", "asia")
What it means
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.
Source
Thrown at clis/rest-countries/utils.js:42
if (!s) throw new ArgumentError(`rest-countries ${label} cannot be empty`);
return s;
}
export function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {
const raw = value ?? defaultValue;
const n = typeof raw === 'number' ? raw : Number(raw);
if (!Number.isInteger(n) || n <= 0) {
throw new ArgumentError(`rest-countries ${label} must be a positive integer`);
}
if (n > maxValue) {
throw new ArgumentError(`rest-countries ${label} must be <= ${maxValue}`);
}
return n;
}
export function requireRegion(value) {
const raw = String(value ?? '').trim().toLowerCase();
if (!raw) throw new ArgumentError('rest-countries region is required (e.g. "europe", "asia")');
if (!REST_COUNTRIES_REGIONS.has(raw)) {
throw new ArgumentError(
`rest-countries region "${value}" is not recognised`,
`Allowed regions: ${[...REST_COUNTRIES_REGIONS].join(', ')}.`,
);
}
return raw;
}
export async function restCountriesFetch(url, label) {
let resp;
try {
resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });
}
catch (err) {
throw new CommandExecutionError(
`${label} request failed: ${err?.message ?? err}`,
'Check that restcountries.com is reachable from this network.',View on GitHub (pinned to 49907e53dc)
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.
Example fix
// before
await regionCommand({ region: '' });
// after
await regionCommand({ region: 'asia' }); Defensive patterns
Strategy: validation
Validate before calling
if (typeof region !== 'string' || !region.trim()) {
throw new TypeError('region is required (e.g. "europe", "asia")');
} Type guard
function isNonEmptyRegion(v) { return typeof v === 'string' && v.trim().length > 0; } Try / catch
try {
await regionCommand({ region });
} catch (err) {
if (err instanceof ArgumentError && /region is required/.test(err.message)) {
printUsage('region is required: africa|americas|asia|europe|oceania');
} else {
throw err;
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Missing CLI flag; an unset environment variable interpolated into the command; interactive scripts where the user skipped the prompt.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- rest-countries ${label} cannot be empty
- archive search sort must be one of ${SORT_OPTIONS.join(', ')
- archive search mediatype must be one of ${MEDIATYPES.join(',
- archive search limit must be a positive integer
- archive search limit must be <= 100
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/3f5282416849ad5e.
Report an issue: GitHub.