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

  1. Provide a region value such as 'europe' or 'asia'.
  2. Validate the input is non-empty before invoking the command.
  3. Fix the calling script/config so the region variable is populated.
  4. 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

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/3f5282416849ad5e. Report an issue: GitHub.