jackwener/OpenCLI · error · ArgumentError

rest-countries region "${value}" is not recognised

Error message

rest-countries region "${value}" is not recognised

What it means

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.

Source

Thrown at clis/rest-countries/utils.js:44

}

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. Use one of: africa, americas, asia, europe, oceania.
  2. Map your internal territory names to the API's region set before calling.
  3. Use the subregion or translation endpoints for finer-grained grouping.
  4. Catch ArgumentError and read err's hint for the allowed list.

Example fix

// before
await regionCommand({ region: 'EMEA' });
// after
await regionCommand({ region: 'europe' }); // or 'asia', 'africa', 'americas', 'oceania'
Defensive patterns

Strategy: validation

Validate before calling

const ALLOWED = new Set(['africa','americas','asia','europe','oceania']);
const normalized = String(region ?? '').trim().toLowerCase();
if (!ALLOWED.has(normalized)) {
  throw new TypeError(`region must be one of: ${[...ALLOWED].join(', ')}`);
}

Type guard

function isApiRegion(v) {
  return ['africa','americas','asia','europe','oceania'].includes(String(v ?? '').trim().toLowerCase());
}

Try / catch

try {
  await regionCommand({ region });
} catch (err) {
  if (err instanceof ArgumentError && /not recognised/.test(err.message)) {
    console.error(err.message, err.hint ?? '');
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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